SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Feb 2013
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery newbie needs help - target only one li and its children?

    Hi,

    I am making a menu, and you can see what I have made so far in this fiddle

    What I want to do is make it so that when I click the first <li> only the sub-menu for this <li> will show, and if I click another <li> I want this one the current one to close and show the new one. Atm clicking another wont close the previous.

    Point me in the right direction?=)

  2. #2
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    318
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Try defining a global variable which stores the active li? Then when one is clicked, check that the global variable has a value, if it does, then hide the li and set the global variable to the new li.

    The value should be that of the li that is clicked. I hope this makes sense XP

  3. #3
    SitePoint Addict
    Join Date
    Feb 2013
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Patche View Post
    Try defining a global variable which stores the active li? Then when one is clicked, check that the global variable has a value, if it does, then hide the li and set the global variable to the new li.

    The value should be that of the li that is clicked. I hope this makes sense XP
    Okey, could you show me how this could look? I am very new to jQuery, but trying to learn.

  4. #4
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    318
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ReGGaeBOSS View Post
    Okey, could you show me how this could look? I am very new to jQuery, but trying to learn.
    http://jsfiddle.net/LGRaB/30/

  5. #5
    SitePoint Addict
    Join Date
    Feb 2013
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Patche View Post
    That is the same one as my fiddle above, did you maybe link the wrong one?=)


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
  •