9

I have code HTML

<input id="info[text1]" type="text" value="1"/> <br>
<input id="info[text2]" type="text" value="2"/> <br>

I want to select id='info[text1]' using jquery but I can't, so can you help me!

Andro Selva
  • 51,960
  • 51
  • 189
  • 237
Đạt Hoài
  • 103
  • 1
  • 1
  • 4

3 Answers3

17

You have to escape the brackets with \\

$("#info\\[text1\\]")

see http://api.jquery.com/category/selectors/ (second paragraph)

st3inn
  • 1,487
  • 9
  • 16
5

Try it this way.

$('input[id="info[text1]"]')
henkieee
  • 1,123
  • 1
  • 8
  • 10
  • Worked for me, add colon before `input` and it works even better ;) $(':input[id="info[text1]"]') - nice one! – Cups May 07 '14 at 13:03
5

Try this:

$('#info\\[text1\\]');

http://jsfiddle.net/UwrVn/

undefined
  • 136,817
  • 15
  • 158
  • 186