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
  • 103,927
  • 20
  • 129
  • 143
Vamshi
  • 8,825
  • 4
  • 35
  • 53

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
  • 142,114
  • 39
  • 237
  • 299
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
  • 103,927
  • 20
  • 129
  • 143