views:

696

answers:

4

I want to do this:

$('input[inputName=someValue]')

Except that the name of the input is not 'inputName', it is 'inputName[]'. And this doesn't work:

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

and neither does this:

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

or this

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

Thanks for any help.

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).

Thanks for all your help.

+1  A: 

The attribute selector syntax is [name=value] where name is the attribute name and value is the attribute value.

So if you want to select all input elements with the attribute name having the value inputName[]:

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

And if you want to check for two attributes (here: name and value):

$('input[name="inputName[]"][value=someValue]')
Gumbo
+2  A: 

You can use backslash to quote "funny" characters in your jQuery selectors:

$('#input\\[23\\]')

For attribute values, you can use quotes:

$('input[name="weirdName[23]"]')

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

Pointy
jQuery documentation stipulates that two backslashes are needed for escaping.
Dancrumb
oh durr you're right - it's not so much for jQuery itself but because Javascript will parse out the single ones! Thanks.
Pointy
@Pointy - voted up following edit
Dancrumb
A: 

Try this:

$('input[name="inputName\\[\\]"]')

You need to escape the brackets [ ] using backslash.

Sarfraz
jQuery escapes with two backslashes
Dancrumb
+2  A: 

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]')
Dancrumb
Good catch. The reason for needing two backslashes is because a single backslash is interpreted as a JavaScript string escape character, so you need two to specify a literal backslash, which provides the escape character to the selector... ah, the joys of multiple levels of character escaping.
Peter