Results 1 to 3 of 3

Thread: jQuery halp

  1. #1
    Penish
    Join Date
    Feb 2012
    Posts
    1,540
    Points
    2,647
         User Info     Contact     Gamer ID
    Join Date
    Feb 2012
    Posts
    1,540
    Points
    2,647

    Default jQuery halp

    Im trying to make it so that when these links are clicked it removes the class="current" from the original li and puts it onto the one that got clicked but its not really working. It removes the original but doesn't add it to the new one

    Here's what is looks like

    http://jsfiddle.net/boxninja2/5hkqa556/3/

    0 Not allowed! Not allowed!

  2. #2
    Damn Daniel JesusLover666's Avatar
    Join Date
    Dec 2009
    Location
    /bin/laden
    Posts
    1,114
    Points
    2,360
         User Info     Contact     Gamer ID
    Join Date
    Dec 2009
    Location
    /bin/laden
    Posts
    1,114
    Points
    2,360

    Default

    Code:
    $(this).parent().addClass('current');
    is adding the class current to the ul (aka the parent).


    Try this: http://jsfiddle.net/JesusLover666/grqf135e/4/ (I modified your HTML a little bit as well)

    Explained: (there are comments in the JS)

    Code:
    $(document).ready(function () {
        $('#menu ul a').click(function () {
            $('#menu ul li.current').removeClass('current'); //To reflect HTML changes
            $(this).parent().addClass('current');
    
            var filterVal = $(this).attr('class'); //Now this will have the value "Test3 current"...
            filterVal = filterVal.split(" "); //So we need to split it into parts
            
            $('#content div').each(function () {
                if ($(this).hasClass(filterVal[0])) {  //Use the first part of the filterVal array
                    $(this).fadeIn(300);
                } else {
                    $(this).hide();
                }
            });
            return false;
        });
    });

    1 Not allowed! Not allowed!

  3. #3
    Penish
    Join Date
    Feb 2012
    Posts
    1,540
    Points
    2,647
         User Info     Contact     Gamer ID
    Join Date
    Feb 2012
    Posts
    1,540
    Points
    2,647

    Default

    Thanks man

    I knew it was going to be something simpleish

    0 Not allowed! Not allowed!

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 01:16 PM.
Powered by vBulletin®
Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.