tags:

views:

54

answers:

2

I'm trying to access elements using jquery $('#elementID') method. If any element contain "." character like

id="element.0" 
id="element.1"

i can't access that element.

Is it because of the "." character in id string ?

+5  A: 

You need to escape the dot with \\

$('element\\.0');

http://api.jquery.com/category/selectors/

jAndy
+7  A: 

It would look like this for the first one:

$("#element\\.0")

However, even though this is valid (thanks to @patrick on the link below, I had my specs mixed up), you might want to consider a different delimiter, like a -, for example id="element-0"...it'll result in much cleaner/less problematic code (since class selectors use .).

Nick Craver
Nick - I'm pretty sure a `.` is valid, just not often used because it also denotes a class in CSS. From HTML 4: `ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").` http://www.w3.org/TR/html4/types.html#type-id
patrick dw
@patrick - Thanks patrick, I completely missed that `.` was valid...I always avoid it because of selector issues like this. I'm not sure whether it's good or not that anything's fair game in HTML5 as long as they're unique.
Nick Craver