1

I'm using a idTabs to build a tab menu and i'm almost there. But how can i add a class when a tab is selected to the li element class=current(which is the parent) if the anchor is class =SELECTED. And when the class in the anchor is SELECTED and element li class is CURRENT i want to remove the current from all other li element

Thanks in advance

$(document).ready(function(){ $("#outer ul").idTabs(); });

<div id="outer">
<ul class="tabby">
    <li><a href="#Home" class="selected">Home</a></li>
    <li><a href="#NewPages">NewPages</a></li>
</ul>


<div id="NewPages" style="display: none;">
    <ul id="subby_NewPages">
        <li>
        <a href="" class="selected">
        <b>Plans</b></a></li>
        <li>
        <a href="">
        <b>Process</b></a></li>
        <li>
        <a href="">
        <b>Stores </b></a></li>
    </ul>
</div>

<div id="Home" style="display: block;">
    <ul id="subby_Home">
        <li>
        <a href="" class="selected">
        <b>Retail</b></a></li>
    </ul>
</div>
1

So the first bit is to find the li you're looking for which in jQuery is done using Selectors. In your case you want a class selector for "selected" and then get the parent object (an li). The selection of a parent is described in this forum post.

Your code will look something like the following

$(".selected").parent().addClass("CURRENT")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.