Friday, February 18, 2011

Selected menu links

By Magesh Kumar   Posted at  1:32 AM   Java Scripts No comments



<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> 

About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

0 comments:

Back to top ↑
Connect with Us

What they says

© 2013 MaGeSH 2 help. WP Mythemeshop Converted by BloggerTheme9
Blogger templates. Proudly Powered by Blogger.