Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Get all checked checkboxes with name

Im trying to get all checked boxes with a name if images[].

I would usually

 imgs = $('input:checkbox[name=images]:checked').map(function() { return this.value; }).get();

The below code is what I have tried and isnt working.

 imgs = $('input:checkbox[name=images[]]:checked').map(function() { return this.value; }).get();
like image 895
IEnumerable Avatar asked Dec 07 '22 06:12

IEnumerable


1 Answers

You should escape the brackets (adding quotes would also avoid the problem, but escaping special characters is still good practice):

imgs = $('input[type="checkbox"][name="images\\[\\]"]:checked').map(function() { return this.value; }).get();
like image 85
adeneo Avatar answered Dec 08 '22 21:12

adeneo