views:

29

answers:

1

How I can set a style of a:visited with javascript or jquery. I know how to set with a regular link like

document.getElementById('a12').style.color = '#ff0000';

But I don't know how it work with a:visited?

+2  A: 

Style properties adjust style attributes which apply to elements, they completely replace selectors

You have two choices.

  • Write your rule-sets in advance, and then design the element to match the selector.

e.g.

.foo:visited {
  color: #f00;
}

document.getElementById('a12').className += ' foo';
  • Dynamically generate rule-sets with selectors that match the element.

See bobince's answer at http://stackoverflow.com/questions/311052/setting-css-pseudo-class-rules-from-javascript

David Dorward
Hi, I tried a trick likedocument.getElementById('tplcss').innerHTML += 'a:hover{color:#FF0000;}';<style type="text/css" id="tplcss">a:visited{color:#FF00FF;}</style>It's work on FF and Chrome, but IE got runtime error. I should follow your link. Thanks
StoneHeart