I have a very simple Javascript (jQuery) code, which just add a class name to the HTML link <a> element when the link is clicked, then use CSS to change the link background to red.
You will see in my code, I defined the background color for HTML link visited, hover, active . The Javascript (jQuery) code is just to addClass() to the <a> link tag to change the background color to red by using CSS if the link has been clicked.
My code is here on jsfiddle, Why it does not work?
—————New problem————————
Seems the thing get different if I put the link inside a table (as a content of <td>), like this code shows, why now the background does not change to red???? (But the font size did change, strange, seems partly highlighted)
First, jQuery objects have
.addClassavailable. So notthis.addClass, but$(this).addClass.$(this)creates a jQuery object from an element.Secondly,
a .highlightmeans: any descendants of<a>elements with a class ofhighlight. You want<a>elements which have that class themselves, so usea.highlight(without the space).http://jsfiddle.net/YJH9g/10/