1

How can I detect that a click event is fired on any checkbox on a page using jQuery? Please also note that on page load, may be checkbox(s) is/are not created but could be created on request. So HTML DOM will be updated in that fashion.

0

5 Answers 5

6
$(":checkbox").on("click", function(){

// your work

} );

also see bind

delegate

live

reference On

Sign up to request clarification or add additional context in comments.

Comments

2

TRy this

$( document ).on( "click", "input[type='checkbox']", function() {
  alert( "check box clicked" );
});

2 Comments

Binding to the document creates for a bunch of unnecessary event listening. It's why jQuery's .live() function was phased out.
You're answer helped in debug. Thanks
1
$(":checkbox").on("click", function(){

// ALL YOUR STUFF

} )

Comments

0

Simply create a function checkboxClick() as -

function checkboxClick() {
    // ---
    // your code goes here
    // ...
}

Now for every checkbox (even when you add them dynamically) add attribute onclick like

<input type="checkbox" onclick="javascript:checkboxClick();" class="checkbox" />

Note : Since javascript works on existing dom elements, even if you do something like jQuery(".checkbox").click(function() {...});, it wont work on dynamicically added elements

Comments

0
$(document).on('click', ':checkbox', function() {
//your code
});

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.