Earl Higgins
Earl Higgins

Reputation: 129

jQuery onClick event

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.

Upvotes: 9

Views: 67977

Answers (4)

webtech
webtech

Reputation: 329

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

Upvotes: 0

David Tang
David Tang

Reputation: 93664

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();
    });
});

Upvotes: 18

SLaks
SLaks

Reputation: 887415

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

Upvotes: 1

Daniel A. White
Daniel A. White

Reputation: 190935

Return false from your function.

Upvotes: 0

Related Questions