11

I have the HTML code

<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?

HoRn
  • 1,458
  • 5
  • 20
  • 25
Đạt Hoài
  • 123
  • 1
  • 1
  • 5

3 Answers3

20

You have to escape the brackets with \\

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

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

st3inn
  • 1,556
  • 9
  • 17
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/

Ram
  • 143,282
  • 16
  • 168
  • 197