how to use javascript to set css pseudo-selector's value?
suppose i want to use javascript to add the following css
p:before{content:"Q: "}
how can that be done? I tried the following but they don't work.
myEle.style.:before='content: "Q: "';
myEle.style.content="Q: ";
in general, how do change the value of css pseudo-selectors? such as a:开发者_运维技巧visited, a:link.
The Pseudo-Selectors can't be changed directly and they are not intended to be changed.
If you want to add content before every element of certain kind, you will have to find all of these elements with javascript and insert this content using the dom functions. This requires a lot code, but there are a lot of helping frameworks like jQuery.
With JQuery you can do that by:
$('p').before('Q: ');
I'm not sure why you'd have a need to set an a:visited with javascript, but jQuery will do you worlds of good for easily selecting pretty much anything you need:
http://api.jquery.com/category/selectors/
精彩评论