views:

35

answers:

2

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.

A: 

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/

Thomas McCabe
A: 

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: ');
Baju
Xah Lee
This is a thing you should do with css since that has a far better performance and functionality. If you really want it: $('a').hover(function(){ $(this).css('text-decoration','underline');},function(){ $(this).css('text-decoration','none');})
Baju