9

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.

2
  • It seems that your form is currently posting back to the same page. Assuming you will never try to submit the form this way, you can use type='button', instead of submit. Commented Apr 17, 2011 at 23:05
  • Huh, still no luck with this method. I changed it to a button type. This is not inside a <form> tag. Does this change anything? I simple made it an input because of how it will be handled later. Commented Apr 17, 2011 at 23:18

4 Answers 4

18

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();
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

you know what.. My function was closed off from the document ready function up above! Thanks, wouldn't have noticed this otherwise.
1

You should add return false; to prevent the browser's default action.

1 Comment

This does not seem to make a difference. Could you show me an example?
0

Return false from your function.

Comments

0

The problem might be that your jQuery is above the form. Try to move it below your HTML.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.