IEnumerable
IEnumerable

Reputation: 3800

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();

Upvotes: 4

Views: 23350

Answers (1)

adeneo
adeneo

Reputation: 318342

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();

Upvotes: 15

Related Questions