penguru
penguru

Reputation: 4380

Accessing element with ID that contains "." character

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 ?

Upvotes: 3

Views: 191

Answers (2)

Nick Craver
Nick Craver

Reputation: 630589

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 .).

Upvotes: 7

jAndy
jAndy

Reputation: 236122

You need to escape the dot with \\

$('element\\.0');

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

Upvotes: 5

Related Questions