[ACCEPTED]-jquery - select all checkboxes with js array name-checkbox

Accepted answer
Score: 64

Escape internal brackets with \\(no space) - it 2 should fix the problem.

This selector works 1 for me:

Score: 16

Try using


No need for @ and use ". Note that 2 the selector outside quotes are '. Otherwise 1 you might cause parse error.

Score: 4

First of all, your name attribute should 18 be used to set +1 elements with the same 17 name. It's practically the same as the id 16 attribute and should be unique per element 15 excepted for references, but that is not 14 the case for you.

Try using the class attribute, it's 13 made for the things you want to do!

another 12 thing is that in your code, you can only 11 set your checkboxes to 'checked', but never 10 to uncheck, this code will set your checkboxes 9 to checked true or false, according to what 8 it gets as attribute from the clicked element.

you 7 can do something like this:

set your check 6 all checkbox with an id

 <input type="checkbox" id="checkAll">

Then set on all checkboxes 5 that should be checked/unchecked a class 4

<input type="checkbox" class="checked">

And the you can do something like this in 3 jQuery

$("#checkAll").click( function(){
 var checkedValue = $(this).attr("checked");
 $("input.checked").attr("checked", checkedValue); });

this will change all checkboxes with 2 class checked to the same checked attribute 1 as the one with id checkAll

Score: 2

This code works fine for me...


More Related questions