Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    jQuery class change

    hello I was hoping I could find some help on a little jQuery script. i have the following html:
    Code:
    <ul class="primaryNav">
        <li class="homeTab"><a class="active" href="">home</a></li>
        <li class="featuredTab"><a class="" href="#" onclick="loadXMLDoc()">featured</a></li>
        <li class="newsTab"><a class="" href="">news</a></li>
        <li class="projectsTab"><a class="" href="">projects</a></li>
        <li class="servicesTab"><a class="" href="">services</a></li>
        <li class="contactTab"><a class="" href="#" onclick="cformShow()">contact us</a></li>
    </ul>
    and what I would like to do is change each <a> class to "active" when its corresponding Tab is clicked on. I have searched everywhere to try and find how to do this and in each example I have seen, they show how to change the <li> class but not the <a>! Any help would be awesome!

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Code:
    $('.primaryNav li').click(function() {
       $('.primaryNav li a').removeClass('active');
       $(this).find('a').addClass('active');
    });

  • Users who have thanked devnull69 for this post:

    malfdawg (06-04-2011)

  • #3
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts
    exactly what i needed. too easy =D thank you so much devnull69


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •