I'm trying to select this element which has square brackets in the name attribute:
<input type="text" name="inputName[]" value="someValue">
I've tried this (which doesn't work):
$('input[inputName[]=someValue]')
and neither does this:
$('input[inputName[]=someValue]')
or this:
$('input["inputName[]"=someValue]')
EDIT: As some of you have pointed out, $('input[inputName=someValue]')
would never work. What I was trying to do was: $('input[name=inputName][value=someValue]')
. (But with []
in the name attribute).
You can use backslash to quote "funny" characters in your jQuery selectors:
For attribute values, you can use quotes:
Now, I'm a little confused by your example; what exactly does your HTML look like? Where does the string "inputName" show up, in particular?
edit fixed bogosity; thanks @Dancrumb
Per the jQuery documentation, try this:
[EDIT] However, I'm not sure that's the right syntax for your selector. You probably want:
If the selector is contained within a variable, the code below may be helpful:
In this case we prefix all special characters with double backslash.
The attribute selector syntax is
[name=value]
wherename
is the attribute name andvalue
is the attribute value.So if you want to select all
input
elements with the attributename
having the valueinputName[]
:And if you want to check for two attributes (here:
name
andvalue
):