jQuery selector for inputs with square brackets in the name attribute

aidan picture aidan · Mar 2, 2010 · Viewed 101.9k times · Source

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&#91;&#93;=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).

Answer

Dancrumb picture Dancrumb · Mar 2, 2010

Per the jQuery documentation, try this:

$('input[inputName\\[\\]=someValue]')

[EDIT] However, I'm not sure that's the right syntax for your selector. You probably want:

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