remp
11-02-2010, 05:40 PM
Hello guys, i have a small question:
i have the following code which i use to change the class for selected state on a navigation bar:
<style type="text/css">
#navigationDiv a {
text-decoration:none;
display:block;
color:black;
margin-bottom:5px;
}
#navigationDiv a.selected {
text-decoration:underline;
}
</style>
<script type="text/javascript">
function highlightLinks(obj) {
var linkList = document.getElementById("navigationDiv").getElementsByTagName("a");
for (i = 0; i < linkList.length; i++) {
linkList[i].className = "";
}
obj.className = "selected";
}
</script>
<div id="navigationDiv">
<a href="#" onclick="highlightLinks(this)" class="">anchor1</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor2</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor3</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor4</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor5</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor6</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor7</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor8</a>
</div>
Now, my problem is that when i click another link, the previous on stays with the "selected" class, how can i modify the javascript to remove the class after i click on another link?
Thank you in advance for your response.
i have the following code which i use to change the class for selected state on a navigation bar:
<style type="text/css">
#navigationDiv a {
text-decoration:none;
display:block;
color:black;
margin-bottom:5px;
}
#navigationDiv a.selected {
text-decoration:underline;
}
</style>
<script type="text/javascript">
function highlightLinks(obj) {
var linkList = document.getElementById("navigationDiv").getElementsByTagName("a");
for (i = 0; i < linkList.length; i++) {
linkList[i].className = "";
}
obj.className = "selected";
}
</script>
<div id="navigationDiv">
<a href="#" onclick="highlightLinks(this)" class="">anchor1</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor2</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor3</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor4</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor5</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor6</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor7</a>
<a href="#" onclick="highlightLinks(this)" class="">anchor8</a>
</div>
Now, my problem is that when i click another link, the previous on stays with the "selected" class, how can i modify the javascript to remove the class after i click on another link?
Thank you in advance for your response.