Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 433
hawkeye Avatar asked Mar 01 '11 11:03

hawkeye


People also ask

How do I select a specific ID in CSS?

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.

Which is the correct selector for an ID?

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.

What is the symbol character for an ID selector?

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 (“#”).

How do you select an element with ID test?

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.


2 Answers

you can do

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

      

like image 183
AGuyCalledGerald Avatar answered Sep 23 '22 21:09

AGuyCalledGerald


you can do it like this

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

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

like image 21
Furqan Hameedi Avatar answered Sep 20 '22 21:09

Furqan Hameedi