The “select all” checkbox to select all checkboxes

Below is what you need for a “select all” checkbox to toggle the rest of the checkboxes. Below assumes your checkboxes all have the name “my_chkboxes[]”.

$('#my_select_all').click(function(){
	$("input[name='my_chkboxes[]']").each(function (index, el) {
		if ($('#my_select_all').is(':checked')) {
			$(el).attr('checked', 'checked');
		}else{
			$(el).attr('checked', false);
		}
	});	
});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s