0

I am trying to change the class of a tab on the dashboard depending upon the page selected. I have 3 tabs in the dashboard like

<div>
    <ul class="menu">
    <li class="MenuDashboard"><a href="#" >Dashboard</a></li>
    <li class="MenuSearch"><a href="#">Search</a></li>
    <li class="MenuAccountSetup"><a href="#">Account Set up</a></li>
    </ul>
</div>

Now I want to highlight the tab when I select that particular tab. By default the 'Dashboard' tab should be highlighted. I have a style class called "current" which highlights the tab. Please advise.

1
  • If you already have a class called "current" that highlights the tab, where's the issue? Commented Feb 22, 2012 at 16:51

1 Answer 1

5

This should work:

$('.menu li').click(function() {
  $(this).addClass('current').siblings().removeClass('current');
});

// Clicks on the first menu item to style it
$('.menu li').eq(0).click();
Sign up to request clarification or add additional context in comments.

2 Comments

Don't forget to add the class to the default tab: <li class="MenuDashboard active"><a href="#" >Dashboard</a></li>
They can also just use the class current and replace all instances of active in this example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.