JQuery (UI): check check detection

How can I get jQuery to 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 this with .click, although this will not work when the user adds a checkbox. I could not find information about this in api docs or while searching the web.

Greetings.

+4
source share
2 answers
 $('#test').bind('change', function(){ if($(this).is(':checked')){ // box was checked } }); 
+11
source

You are looking for a change event :

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

Source: https://habr.com/ru/post/1313396/


All Articles