Cant seem to get this working. Any help would be great. I am somewhat of a beginner with jquery.
$('#add_button').click(function () {
$("#add_button").hide();
});
Here is the HTML
<input id='add_button' type='submit' class='add_now' value='' />
Seems simple enough, but clicking on the input does nothing. Is there a different method for targeting inputs? Thanks.
To trigger the onclick function in jQuery, click() method is used. For example, on clicking a paragraph on a document, a click event will be triggered by the $(“p”). click() method. The user can attach a function to a click method whenever an event of a click occurs to run the function.
So, using a string that is tied to a function, onclick produces an attribute within the binded HTML tag. . click, on the other hand, attaches the function to the property element.
click() shorthand is deprecated at jQuery 3 on() and . trigger() methods can set an event handler or generate an event for any event type, and should be used instead of the shortcut methods.
The onclick event executes a certain functionality when a button is clicked. This could be when a user submits a form, when you change certain content on the web page, and other things like that. You place the JavaScript function you want to execute inside the opening tag of the button.
Make sure you include jQuery before your script:
<script src="http://code.jquery.com/jquery-latest.js"></script>
And put your code inside a document-ready function:
$(document).ready(function () {
$('#add_button').click(function () {
$("#add_button").hide();
});
});
You should add return false;
to prevent the browser's default action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With