ID选择器中的jQuery点? [英] jQuery dot in ID selector?

查看:65
本文介绍了ID选择器中的jQuery点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何当ID包含一个点时,通过ID用jquery选择html节点?

Possible Duplicate:
How to select html nodes by ID with jquery when the id contains a dot?

我有一个网站,其中包含与此相似的元素:

I have a website that contains elements similar to this:

<p id="root.SomeCoolThing">Some Cool Thing</p>

我无法选择像$('#root.SomeCoolThing')这样的带有jQuery的段落,因为jQuery认为SomeCoolThing是带有id="root"的元素的类.

I can not select the paragraph with jQuery like $('#root.SomeCoolThing') because jQuery thinks, SomeCoolThing is the class of an element with id="root".

如何使用jQuery选择此元素?我想避免这样的构造:

How can I select this element with jQuery? I would like to avoid a construction like this:

$(document.getElementById('root.SomeCoolThing'))

推荐答案

使用 jQuery选择器API 如下:

$('#root\\.SomeCoolThing') 

文档:

使用任何元字符(例如 !"#$%&'()*+,./:;<=>?@[\]^`{|}~)作为名称的文字部分,它必须 用两个反斜杠转义:\\.例如,具有 id="foo.bar",可以使用选择器$("#foo\\.bar").

To use any of the meta-characters (such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~) as a literal part of a name, it must be escaped with with two backslashes: \\. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar").

这篇关于ID选择器中的jQuery点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆