开发者

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 o开发者_如何学运维f the "." character in id string ?


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


You need to escape the dot with \\

$('element\\.0');

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜