5

I have an id with a dot ('.') . I am not able to select it using jQuery.

For example:

 <p id="sec.ond">this is another  paragraph</p>

How can I use such an id to select this element?

I get such ids while I use spring forms with arrays, e.g.:

<form:input path="abc[0].firstName" />

This will result in:

<form:input id="abc0.firstName" name="abc[0].firstName" />

Thanks in advance for any help.

Donut
  • 110,061
  • 20
  • 134
  • 146
Vamshi
  • 9,194
  • 4
  • 38
  • 54

2 Answers2

5

You can escape it to select it in jQuery.

Example:

$('#sec\\.ond').doSomething()

Fiddle: http://jsfiddle.net/maniator/C7qhF/
See Also: How do I get jQuery to select elements with a . (period) in their ID?

Community
  • 1
  • 1
Naftali
  • 144,921
  • 39
  • 244
  • 303
3

Use two backslashes before the period to escape it, e.g.:

$('#sec\\.ond')

See "How do I select an element by an ID that has characters used in CSS notation?" in the jQuery FAQ.

Donut
  • 110,061
  • 20
  • 134
  • 146