How to trigger checkbox click event even if it's checked through Javascript code?

Jishnu A P picture Jishnu A P · Jan 24, 2011 · Viewed 167.2k times · Source

I have many checkboxes in my page and there is a select all checkbox which checks all the checkboxes. Somehow I want to emulate that click event of checkbox even if it's checked/unchecked through select all button. How can I do it?

Answer

Mark Robinson picture Mark Robinson · Jan 24, 2011

You can use the jQuery .trigger() method. See http://api.jquery.com/trigger/

E.g.:

$('#foo').trigger('click');