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

2019-01-14 10:56发布

问题:

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