5

How can I make jQuery fire an event when a user checks a checkbox?

<input type="checkbox" id="test" name="test" /><label for="test">Check me</label>

I could do it with .click though that doesn't work when the user tabs to the checkbox. I wasn't able to find info on this in the API docs or while Googling.

2 Answers 2

12
$('#test').bind('change', function(){
    if($(this).is(':checked')){
        // box was checked
    }
});
Sign up to request clarification or add additional context in comments.

Comments

4

You're looking for the change event:

$('#test').change(function() { ... });

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.