Checking checkboxes - jQuery

Been through a million blogs, examples etc and I can’t for the life of me figure out why this doesn’t work:

var ids = new Array({$js_string});

$('#check_all').click(function()	 {
	$.each(ids, function()	{

		if ($('#' + this).is(':checked'))	{
			$('#' + this).attr('checked', true);
		else	{
			$('#' + this).attr('checked', false);

	return false;

BTW, the array that is created is done in PHP. I have done alerts inside the if and the else and they fire fine and the ids are there, it’s the code to check them that isn’t working and I just don’t get it!

Any pointers would sure be appreciated


if ($('#' + this).is(':checked')) {
	$('#' + this).attr('checked', 'checked');
} else {
	$('#' + this).removeAttr('checked');

Yeah, sorry, I should have mentioned I tried that … no love there either :wink:

If the checkbox is already checked, then you make it checked.
Else, if the checkbox is not checked, then you make it not checked.

That’s what your code is doing, which doesn’t change things at all.

Have a think about what you actually want to occur instead.


There is is, as plain as the nose on my face!

That’s what happens when I stare at code too long (or as my wife would say: “you want to hide something from him? Put it right under his nose”)

Thanks for the extra eyes … that’s what I needed!

Thanks Paul, maybe I needed a second set of eyes too!

Don’t think it was just you and I … 56 views on this thread and only Paul caught it :wink: