Jump to content

Link Hover States


Rich57

Recommended Posts

I would like to differentiate between(a) internal links that open in the same window, and(B) external links that open in a new windowby using a specific hover background colour. I know I can combine pseudo-classes and classnames from a w3schools example: a.classname:hover{}. However, this would involve adding a class to all my external links.All my external links have the target="_blank" attribute, but my attempts at using an attribute selector (e.g. a[target=_blank]:hover {}) and an independent attribute selector (e.g. target:hover {}) have failed. Should either of these work, or are they not widely supported? I'm using IE6 and Firefox 1.5.Richard

Link to comment
Share on other sites

All my external links have the target="_blank" attribute, but my attempts at using an attribute selector (e.g. a[target=_blank]:hover {}) and an independent attribute selector (e.g. target:hover {}) have failed. Should either of these work, or are they not widely supported?
I don't know anything about a[target=_blank] - I've never seen that before - but you could use a javascript function to dynamically add classnames to your links on page load. This way you could use the traditional a.ExternalClassName:hover and a.InternalClassName:hover. Here's an example:
function HighlightAnchors(){	var anchors = document.getElementsByTagName("a");	var count = anchors.length;	var anchor;	for(var i = 0; i < count; i++)	{		anchor = anchors[i];		if(anchor.target == "_blank")		{			anchor.className = "External";		}		else		{			anchor.className = "Internal";		}	}}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...