Home > Web Front-end > JS Tutorial > How to Correctly Select Inputs with Square Brackets in their Name Attribute using jQuery?

How to Correctly Select Inputs with Square Brackets in their Name Attribute using jQuery?

Mary-Kate Olsen
Release: 2024-11-29 03:12:13
Original
243 people have browsed it

How to Correctly Select Inputs with Square Brackets in their Name Attribute using jQuery?

jQuery Selector for Inputs with Square Brackets in Name Attribute

When attempting to select input elements with square brackets in the name attribute, such as:

<input type="text" name="inputName[]" value="someValue">
Copy after login

using the following selectors may fail:

$('input[inputName[]=someValue]')
$('input[inputName&amp;#91;&amp;#93;=someValue]')
Copy after login

To correctly select such elements, use this syntax:

$('input[inputName\[\]=someValue]')
Copy after login

Note: This syntax prevents confusion with the name attribute containing the square brackets, as in:

$('input[name="inputName[]"][value="someValue"]')
Copy after login

The above is the detailed content of How to Correctly Select Inputs with Square Brackets in their Name Attribute using jQuery?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template