How to remove an image input type using jQuery

Can anyone provide insight into the issue with these scripts? I am attempting to remove an input when it is clicked. The input is of type image, so CSS cannot be used. I have tried using JavaScript but it doesn't seem to be working.

HTML

<!doctype html>
<link rel="stylesheet" href="styles.css">
<title>Site Maintenance</title>
<body>
<article>
<div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script>
<script src="a.js"></script>

<img src="logo.png" alt="logo">
<div id="button1"><a href="#button1" id="w"><input class="do-hide" onclick="window.open('http://www.website.com/page')" type="image"     src="button.png" /></div>
<div id="1button2"><a href="#button2" id="b"><input class="do-hide" type="image" id="button2" src="button1.png" /></a></div>
<div id="1button3"><a href="#button3" id="c"><input class="do-hide" type="image" id="button3" src="button3.png" /></a></div>
<div id="1button4"><a href="#button4" id="d"><input class="do-hide" type="image" id="button4" src="button5.png" /></a></div>
<div id="1button5"><a href="#button5" id="e"><input class="do-hide" type="image" id="button5" src="button4.png" /></a></div>
</div> 
</article>
</body>

JS

$('body').on('click','a.do-hide',function(event) { 
      event.preventDefault(); 
      var href = $(this).attr('href');
      $(href).hide();
});

CSS

a { display:block; }

input.hideable{
display:block;
border:1px solid #AAA;
}

.hideable:target {
display:none;
}

body { text-align: center; padding: 150px; background-image: url("b.png"); }
body { font: 20px Helvetica, sans-serif; color: #666a73; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
#button1 {
height: 50px;
width: 250px;
position: absolute;
left: 300px;
top: 500px;
opacity: 0.6;
}
#button1:hover {
width: 270px;
height: 60px;
}
#w:target {
display: none;
}
#button2 {
height: 50px;
width: 250px;
position: absolute;
left: 600px;
top: 500px;
opacity: 0.6;
}
#button2:hover {
width: 270px;
height: 60px;
}
#b:target {
width: 0px;
height: 0px;
}

#button3 {
height: 50px;
width: 250px;
position: absolute;
left: 900px;
top: 500px;
opacity: 0.6;
}
#button3:hover {
width: 270px;
height: 60px;
}
#c:target {
width: 0px;
height: 0px;
}

#button4 {
height: 50px;
width: 250px;
position: absolute;
left: 1200px;
top: 500px;
opacity: 0.6;
}
#button4:hover {
width: 270px;
height: 60px;
}
#d:target {
width: 0px;
height: 0px;
}

#button5 {
height: 50px;
width: 250px;
position: absolute;
left: 1500px;
top: 500px;
opacity: 0.6;
}
#button5:hover {
width: 270px;
height: 60px;
}
#e:target {
width: 0px;
height: 0px;
}

img {
position: absolute; 
left: 520px;
top: 100px;
opacity: 0.9;
}

Answer ā„–1

The selector you are using is incorrect. When you use a.do-hide, it searches for an <a> element with a class of do-hide. Instead, you should be looking for the element with class do-hide as a child of an <a>, so there should be a space between the selectors. You can then hide the element using $(this).hide(). Try this:

$('body').on('click', 'a .do-hide', function(event) {
  event.preventDefault();
  $(this).hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<img src="logo.png" alt="logo">
<div id="button1">
  <a href="#button1" id="w">
    <input class="do-hide" onclick="window.open('http://www.website.com/page')" type="image" src="button.png" />
</div>
<div id="1button2">
  <a href="#button2" id="b">
    <input class="do-hide" type="image" id="button2" src="button1.png" />
  </a>
</div>
<div id="1button3">
  <a href="#button3" id="c">
    <input class="do-hide" type="image" id="button3" src="button3.png" />
  </a>
</div>
<div id="1button4">
  <a href="#button4" id="d">
    <input class="do-hide" type="image" id="button4" src="button5.png" />
  </a>
</div>
<div id="1button5">
  <a href="#button5" id="e">
    <input class="do-hide" type="image" id="button5" src="button4.png" />
  </a>
</div>
</div>

Answer ā„–2

If you want to conceal the input field, try applying this method

$(".hide-field").click(function(){
    $(this).hide();
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigating through a collection of objects

My array consists of objects, each having the following structure: var car = { make: "", model: "", price: "" } I am attempting to iterate through each object and check if a specific property is defined in this manner: for (i = 0; i <= ...

Issue encountered: Inability to implement asynchronous functionality within a forEach loop while making an API request

When making a GET API call, the code looks like this router.get('/review', async (req, res) => { try { const entity = await Entity.find(); const entityId = []; Object.keys(entity).forEach((key) => { entityId.push(entity[ ...

Issue with AdminLite 2.4.0 data table functionality malfunctioning

Check out this template that I'm using. I've copied all the contents for the bower_components and dist folders, and made sure to link and require everything properly. There are no 404 errors, only status code 200. Here is a snippet of my code: ...

In what way can I successfully trigger the submission of a form when clicking on a span element, utilizing AJAX to prevent the page from refreshing? At the same time, I would like to

Can I submit a form by clicking on a span element without refreshing the page? I also want to include a regular submit button for mobile view, but it only works when directly submitting the form. Is there a way to use ajax to submit the form when clicking ...

What is the best way to showcase navigation and footer on every page using AngularJS?

I'm in the process of building a Single Page Application. I've decided to create separate components for Navigation, Section, and Footer. The Navigation and Footer should be displayed on every page, while only the Section content changes when nav ...

Arrays Filtering without Containing Elements

Is there a utility function in Knockout to filter one array based on another array, or will I need to use JavaScript? First : var obj1 = [{ "visible": "true", "id": 1 }, { "visible": "true", "id": 2 }, { "visible": "true", "id": ...

Retrieve the height of an element containing images, even if the images have not finished loading

After making an Ajax call and inserting some HTML code, I require the height of the newly added div in the Ajax callback. However, the issue arises because the HTML from the Ajax call contains elements like images that need to be loaded first. I have crea ...

What are the best methods for adjusting the size of a game's

I create games using HTML5/CSS/JS, but I am struggling to figure out how to make them scale to different screen resolutions. It seems like a simple task, but I can't seem to grasp it. SOLVED var RATIO = 480 / 800; // Initial ratio. function resize() ...

Smooth-scroll plugin does not activate active state (due to JS modification)

I'm currently facing an issue with a script that handles smooth scrolling and the active state on my main navigation. The plugin in question can be found at: It's important to note that the navigation bar is fixed and therefore has no height. T ...

Is it possible to adjust the range of a range slider based on the selection of a radio button or other input method?

I have a query and Iā€™m hopeful you can assist: function UpdateTemperature() { var selectedGrade = $( "input[name='radios']:checked" ).val(); $( ".c_f" ).text(selectedGrade); var value1 = $("#tempMin").val(); var value2 = $("#tempM ...

Position the input element in the middle of the div

Is it possible to center a form input element within a div element without it changing position when the browser window size is adjusted? I attempted using margin: auto and position: relative, but encountered issues with the element moving. How can this be ...

How is it possible to encounter a Javascript unexpected token ] error within an HTML code?

While working on my project, I encountered a JavaScript error in the console of Chrome. The error message stated "Unexpected token ]" and it was pointing to a specific line of raw HTML code. I am puzzled about what could be causing this issue. Unfortunatel ...

The div element on my website spans the entire width, yet it appears slightly narrower than the body

My website features a scrolling div element that spans 100% of the screen, but I am encountering an issue with slight horizontal scrolling and the background image extending beyond the visible area. I am striving to adjust the width of the div so that it ...

I need help figuring out how to handle click events when using VueJS 2.0 in conjunction with a vue-mdl menu component

While @click doesn't seem to respond, v-bind:click does register. However, I'm facing the challenge of not being able to access the mdl-menu or mdl-menu-item components in order to add the method. The goal is to implement something like @click=" ...

How can I effectively refresh the provider_token / access token for Discord in NextJS with Supabase Auth?

Currently, I have encountered an issue with my NextJs project using Supabase Auth for authentication. I am currently utilizing the Discord provider and everything works fine initially. However, after a few minutes, the session object gets updated and the p ...

Node.JS 3DES encryption encountering an issue with IV length validation

I'm new to working with Node.js and I've encountered an issue with the encryption object: var des3_key = new Buffer("redacted", "base64"); // obtained from another source var des3_iv = new Buffer("alsoredacted", "base64"); // obtained from anoth ...

Is it possible for me to utilize jquery and AJAX to invoke a cgi-bin script, and then incorporate a message event to manage Server Sent Event?

I have a cgi-bin program that runs for a long time (3-15 minutes) and I am looking to invoke it using AJAX. While the program is running, I want to receive Server Sent Event data from it and display it on my web page. It's like having a progress monit ...

Divide the MySQL results into two distinct groups and display them in separate div

I have a MySQL query that fetches all the topic results. I have also implemented a pagination system where the results are divided into pages, and the query's limit #,# varies depending on the current page. My goal is to organize these results into t ...

Tips on allowing a rectangle to be draggable using HTML5

I have been experimenting with resizable and draggable rectangles in HTML5. I've managed to create resizable rectangles, but I am having trouble getting them to drag using mouse events. You can view my JSFiddle code at the following link: here. / ...

Collaborative spreadsheet feature within a browser-based software platform

I am using an Angular-based SPA for my web application. My goal is to be able to open an Excel file within the application itself. Currently, I have a menu button or link that is linked to a specific path, for example //192.168.10.10/sharedExcels/myExcel. ...