1

I have used the following code to display menu

<ul id="menu">
    <li id="11"><a href="#1" class="cross-link cross-link1">Start a League</a><span></span></li>
    <li id="12"><a href="#2" class="cross-link cross-link1">Roster Settings</a><span></span></li>
    <li id="13"><a href="#3" class="cross-link cross-link1">Draft Settings</a><span></span></li>
    <li id="14"><a href="#4" class="cross-link cross-link1">Transaction Settings</a><span></span></li>
    <li id="15"><a href="#5" class="cross-link cross-link1">Playoff Settings</a><span></span></li>
    <li id="16"><a href="#6" class="cross-link cross-link1">Launch Your League!</a><span></span></li>
</ul>

If I click any menu the class active should be added in that particular li. How can i do it with javascript.

1 Answer 1

7

Using jQuery:

$("li").click(function() {
    $("li").removeClass("active");
    $(this).addClass("active");
});

I supposed that you only wanted a single <li> with the active class.

Demo: http://jsfiddle.net/j9qTE/1/

Sign up to request clarification or add additional context in comments.

Comments

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.