18

The element:

<input type='text' id='Customer.name' value='' />

The invalid jQuery selector:

$('#Customer.name')

Does anyone know what the selector should be for this element?

Jimbo
  • 22,379
  • 42
  • 117
  • 159
  • 4
    [Question 6](http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_select_an_element_by_an_ID_that_has_characters_used_in_CSS_notation.3F) from jQuery FAQ. – GSerg Jul 15 '11 at 07:47
  • 2
    FYI, if you have any influence over the content, it's certainly best to stay away from punctuation in id names: http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html – jfriend00 Jul 15 '11 at 07:58

3 Answers3

20
$('input[id="Customer.name"]')

Example: http://jsfiddle.net/AlienWebguy/HFpEE/

AlienWebguy
  • 76,997
  • 17
  • 122
  • 145
  • if there a way to get teh element by css #Customer.name{ ...} doesnot work,!! ay way to get it by css – Imen Jan 15 '21 at 16:11
19

You can escape the period character with two backslashes:

$('#Customer\\.name')
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • 1
    This selector is perfectly valid although in IE9 even when the html element is there, `$('#Customer\\.name').length` returns 0. However, `$('input[id="Customer.name"]')` returns 1 (!?!) – Jimbo Jul 18 '11 at 07:51
5

From the jquery documentation:

$("#Customer\\.name")

jQuery FAQ

Jacob van Lingen
  • 8,989
  • 7
  • 48
  • 78