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?
The CSS id Selector The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.
The selector must start with a pound sign ( # ) and then the value of the id attribute. The browser will then look for a tag in the page that has an id attribute equal to that id.
In the CSS, a class selector is a name preceded by a full stop (“.”) and an ID selector is a name preceded by a hash character (“#”).
The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.
you can do
$("#\\/about-us")
you can do it like this
$("span[id*='/about-us']")
where it will return the span with '/about-us' in it's id attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With