Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

How do I apply class="current" to menu items?

I know how to do it in static form.

How would it be applied to a menu item in a dynamic fashion.

so that the menu item, when clicked, gets class="current" applied to the

below code


HTML
<li id="liFamily" class="current"><a href="">By Family</a></li>
<li id="liIndividual"><a href="#">By Individual</a></li>
<li id="liSeating" ><a href="#">By Seating</a></li> 


Here i apply statically, i want to do that dynamically
Posted
Updated 22-Dec-11 0:53am
v3

You must use the selectors(A:link, A:visited, A:active, A:hover) of Anchor Tag. Check this tutorial for more details.

CSS Links[^]
 
Share this answer
 
Comments
Monjurul Habib 22-Dec-11 14:51pm    
5!
You can use a asp:ListView to bind to a datasource. In the itemtemplate you can add a the class attribute when the current item is selected.
 
Share this answer
 
by server side
you should add "runat=server" attribute with li

ASP.NET
<ul><li id="liFamily" runat="server" class="current"><a href="">By Family</a></li></ul>


Now you can access this on Server Side

if you want to do it on client side
you should use javascript function at the last of the page
and you should khow about current menu then you can add attribute..
make function as globla; and call function on each page at the last
with current menu.
JavaScript
function setmnu(mnuid)
{
   var mnu=document.getElementById(mnuid);
   mnu.className="current";
}
setmnu('liFamily');


ok
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900