faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

15 of 24 people (63%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How to make link bold on click, while simultaneously resetting last clicked link to normal?

Oct 11th, 2001 08:56
Dave Pedowitz, Jesper Bierbum,


This can easily be accomplished in IE and NS6, unforntunately you 
cannot dynamically change a links style properties in NS4.
For IE and NS6 you can loop through the links on your page and 
dynamically change style elements.
<html>
<head>
	<title>Untitled</title>
</head>
<script language="JavaScript">
var d = document;
//Simple browser detect
this.ns4 = d.layers?1:0;
this.dom = d.getElementById?1:0;
function changeClass(whichLink) {
	//Loop through the link id's creating objects for DOM and IE
	for (i = 0; i < d.links.length; i++) {
		this.dom?this.linkObj = d.getElementById(d.links
[i].id):this.linkObj = d.all[d.links[i].id];
		if (linkArray[i] == whichLink) {
			this.linkObj.style.fontWeight = "bold";
		} else {
			this.linkObj.style.fontWeight = "normal";
		}
	}
}
</script>
<style type="text/css">
.text {font-family:Arial, Helvetica; font-size:12px; font-
weight:normal; color:#000000;}
.text:hover {font-family:Arial, Helvetica; font-size:12px; font-
weight:normal; color:#660000;}
</style>
<body>
<a href="javascript: changeClass('link1')" class="text" 
id="link1">Link1</a>
<p>
<a href="javascript: changeClass('link2')" class="text" 
id="link2">Link2</a>
<p>
<a href="javascript: changeClass('link3')" class="text" 
id="link3">Link3</a>
<p>
<a href="javascript: changeClass('link4')" class="text" 
id="link4">Link4</a>
</body>
</html>