Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using & in CSS selectors [closed]

I have a div with id as masterResourceFor_R&D. But when I use this ID in jQuery to select this div and put a click function on it, it doesn't work. I think the problem is because of the symbol & in ID. I do not have any option to rename the ID.

How can I use this ID in jQuery?

like image 758
Narayan Singh Avatar asked Oct 23 '13 07:10

Narayan Singh


People also ask

What is the English meaning of uses?

transitive verb. 1 : to put into action or service : avail oneself of : employ. 2 : to expend or consume by putting to use —often used with up. 3 : stand sense 1d the house could use a coat of paint. 4 : to consume or take (liquor, drugs, etc.)

What is the verb of using?

verb (used with object), used, us·ing. to employ for some purpose; put into service; make use of: to use a knife. to avail oneself of; apply to one's own purposes: to use the facilities. to expend or consume in use: We have used the money provided.

What is the word for using someone?

An exploiter is a user, someone who takes advantage of other people or things for their own gain. Being an exploiter is selfish and unethical. To exploit someone is to use them in a way that's wrong, like an employer who pays low wages but demands long hours.


2 Answers

You can escape the character using backslashes (\).

CSS

#masterResourceFor_R\&D { ... }

jQuery

$('#masterResourceFor_R\\&D');

JSFiddle demo.

like image 125
James Donnelly Avatar answered Oct 30 '22 01:10

James Donnelly


Ignore using special characters as id's and class names, change it if you can, if you can't and you want to solve this mess, you need to escape that character

#masterResourceFor_R\&D {
   color: red;
}

Demo

Reference

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B\&W\?" or "B\26 W\3F".

like image 4
Mr. Alien Avatar answered Oct 30 '22 01:10

Mr. Alien