I've got <span id="/about-us">
being generated by this CMS I'm using.
我已经使用了这个CMS生成的。
I'd like to select this element with jQuery but it doesn't seem to like selecting elements with a slash in them.
我想用jQuery选择这个元素,但它似乎不喜欢选择带有斜线的元素。
Is this possible?
这是可能的吗?
4 个解决方案
#1
35
you can do
你可以做
$("#\\/about-us")
#2
27
you can do it like this
你可以这样做
$("span[id*='/about-us']")
where it will return the span with '/about-us' in it's id attribute.
在id属性中返回带有'/ aboutus '的span。
#3
11
Use the regular way:
用常规的方法:
document.getElementById('id/with/slashes')
#1
35
you can do
你可以做
$("#\\/about-us")
#2
27
you can do it like this
你可以这样做
$("span[id*='/about-us']")
where it will return the span with '/about-us' in it's id attribute.
在id属性中返回带有'/ aboutus '的span。
#3
11
Use the regular way:
用常规的方法:
document.getElementById('id/with/slashes')