<script type="text/javascript"> | |
function applySelectedTo(link) { | |
var ul = document.getElementsByTagName("ul")[0]; // get the first ul tag on the page | |
var allLinks = ul.getElementsByTagName("a"); // get all the links within that ul | |
for (var i=0; i<allLinks.length; i++) { // iterate through all those links | |
allLinks[i].className = ""; // and assign their class names to nothing | |
} | |
link.className = "selected"; // finally, assign class="selected" to our chosen link | |
} | |
</script> |
Where the code in html is:
<ul> | |
<li><a onclick="applySelectedTo(this);return false;" href="#" class="">xxxx </a></li> | |
<li><a onclick="applySelectedTo(this);return false;" href="#" class="">yyyy </a></li> | |
<li><a onclick="applySelectedTo(this);return false;" href="#" class="">zzzz </a></li> |
</ul>
0 comments: