0

How can I use jquery to select the checkbox that has an array value in its attribute name?

html,

<input type="checkbox" name="delete[]" value="1"/>

My attempt that does not work,

$('input:checkbox[name=delete]',container).not('input:checkbox[disabled=disabled]').prop('checked', true);

Any ideas?

2 Answers 2

1

You can do this:

$('input:checkbox[name^=delete]',container)

or this:

$('input:checkbox[name="delete[]"]',container)

or this:

$('input:checkbox[name=delete\\[\\]]',container)
Sign up to request clarification or add additional context in comments.

Comments

1

In this case, since you're checking an attribute value, you can just wrap the value in double quotes (anything within the quotes is treated literally):

$('input:checkbox[name="delete[]"]')

Or more generally, escape the special characters:

$('input:checkbox[name=delete\\[\\]]');

The method for escaping, and the list of special characters, is covered at the start of the documentation for Selectors.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.