Home >Web Front-end >JS Tutorial >How to Select Input Elements with Brackets in the Name Attribute Using jQuery?
When attempting to select input elements with square brackets in the name attribute, using regular expressions can be challenging. Let's explore alternative methods to achieve this in jQuery.
The HTML code provided includes an input element with a name attribute that contains square brackets:
<input type="text" name="inputName[]" value="someValue">
Attempted but Unsuccessful Selectors
Solution
As per jQuery documentation, we can use the following syntax to select the desired element:
$('input[inputName\[\]=someValue]')
Alternative Selector
However, the original intention may be to select the element based on both name and value attributes. In that case, the correct syntax would be:
$('input[name="inputName[]"][value="someValue"]')
With this revised selector, you can successfully query input elements that have square brackets in their name attribute and a specific value attribute.
The above is the detailed content of How to Select Input Elements with Brackets in the Name Attribute Using jQuery?. For more information, please follow other related articles on the PHP Chinese website!