SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: <li> problem

  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,147
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post <li> problem

    Hi, I have 3 <li> inside the <ul>,everytime i clicked i want to put a class name

    Code:
       $(function(){
    
               $('#li-one').click(function(event){
                   event.preventDefault();
    
                   $('#li-one').addClass('colorstyle').closest('li').nextAll('.selected').removeClass();
    
    
                   $('.content').load('add.php');
    
               })
    
            });
    
    
    $(function(){
    
               $('#li-two').click(function(event){
                   event.preventDefault();
    
                   $('#li-two').addClass('colorstyle').closest('li').nextAll('.selected').removeClass();
    
    
                   $('.content').load('add.php');
    
               })
    
            });
    
    $(function(){
    
               $('#li-three').click(function(event){
                   event.preventDefault();
    
                   $('#li-three').addClass('colorstyle').closest('li').nextAll('.selected').removeClass();
    
    
                   $('.content').load('add.php');
    
               })
    
            });
    what i want is that if i am going to click li-two the li-one should remove the class name which is .colorstyle,but my code is not working.

    Thank you in advance.

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Looks like this works. Not my fiddle http://jsfiddle.net/35QaP/

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,147
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi EricWatson, Works great thank you.


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
  •