1

I have a select dropdown that has a name attribute[12], how can I use jquery to get that element by its name only?

<select name="attribute[12]"></select>

Currently I am trying to access it by using:

$('select[name="attribute[12]"]')
1
  • 1
    It should work. What is the issue? jsfiddle.net/Fnqv8 Commented Dec 4, 2013 at 17:28

1 Answer 1

1

Try this,

$('select[name="attribute\\[12\\]"]')

Your select tag's name is containing two meta-characters [ and ]. You have to escape it in order to make your selector working. Please read here for full reference.

Sign up to request clarification or add additional context in comments.

2 Comments

@j08691 weird, maybe the version of jquery i'm using is older, but that shouldn't be the case
@j08691 As far I have learnt, Escaping the meta-characters are the good practice and the right method. But I am curious to know how is that working.? any ideas.?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.