ID选择器中的jQuery点? [英] jQuery dot in ID selector?
问题描述
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 withid="foo.bar"
, can use the selector$("#foo\\.bar")
.
这篇关于ID选择器中的jQuery点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!