CSS selector to select an id with a slash in the i

2019-01-14 10:41发布

I've got <span id="/about-us"> being generated by this CMS I'm using.

I'd like to select this element with jQuery but it doesn't seem to like selecting elements with a slash in them.

Is this possible?

4条回答
Lonely孤独者°
2楼-- · 2019-01-14 11:02

you can do

$("#\\/about-us")

      

查看更多
霸刀☆藐视天下
3楼-- · 2019-01-14 11:07

you can do it like this

     $("span[id*='/about-us']")

where it will return the span with '/about-us' in it's id attribute.

查看更多
劳资没心,怎么记你
4楼-- · 2019-01-14 11:14

Use the regular way:

document.getElementById('id/with/slashes')
查看更多
登录 后发表回答