How do I set CSS properties of .anyclass:before or .anyclass:after via javascript?
How do I set CSS properties of .anyclass:before or .anyclass:after via javascript?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Expanding on my comment:
:beforeand:afterare not properties, they are CSS selectors. Therefore you cannot set them on some element, you can only add rules with such selectors to a stylesheet.If you want to add DOM nodes before or after all elements that match a given selector with jQuery, you can use the
beforeandaftermethods respectively.If you want to add CSS rules to the current page, you can use the DOM level 2 CSSStyleSheet interface. A minimal example would look like this:
See the MDN documentation for
insertRulefor more example code.