jquery - select all checkboxes with js array name jquery - select all checkboxes with js array name arrays arrays

jquery - select all checkboxes with js array name


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

This selector works for me:

$('input[name=items\\[\\]]')


Try using

$('input[name="items[]"]')

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


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

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

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

you can do something like this:

set your check all checkbox with an id

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

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

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

And the you can do something like this in jQuery

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

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