George Stephanis

July 13, 2011

Toggle All Checkboxes with jQuery

Filed under: Javascript, jQuery, Plugin — Tags: , — George Stephanis @ 11:54 am

Just a little snippet I worked up that may be useful to someone …

$('div#checkall-wrapper input[type=checkbox]').click(function(){
	if( $(this).attr('checked') ){
		$('tdiv#wraparound-targets input[type=checkbox]').attr('checked','checked');
		$('div#wraparound-targets input[type=checkbox]').removeAttr('checked');

Make sense?


  1. Nice tip!

    This is how I would have done it in your case:

    targets = $('div#wraparound-targets input[type=checkbox]');
    $(this).attr('checked') ? targets.attr('checked', 'checked') : targets.removeAttr('checked');

    Comment by Chris — November 15, 2011 @ 11:13 am

  2. Yup, makes sense. I just know that a lot of people have a hard time understanding the ternary operator, so I wrote it out longhand.

    Comment by George Stephanis — November 15, 2011 @ 11:44 am

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

The WordPress Classic Theme. Blog at


Get every new post delivered to your Inbox.

Join 2,444 other followers

%d bloggers like this: