CSS selector to select an id with a slash in the id name?

坚强是说给别人听的谎言 提交于 2019-12-17 10:52:14

问题


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?


回答1:


you can do

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

      




回答2:


you can do it like this

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

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




回答3:


Use the regular way:

document.getElementById('id/with/slashes')



回答4:


see

Regex Selector for jQuery

or related question




回答5:


You can use jQuery escapeSeletor to do this.

$("#" + $.escapeSelector("id/with/slashes"))


来源:https://stackoverflow.com/questions/5153986/css-selector-to-select-an-id-with-a-slash-in-the-id-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!