SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Toggling child elements on parent click

    Hey folks,
    i am new at JS and jQuery and trying to make this code work. But i can't solve the problem. when u click on parent of nested list items.It hide the unordered list too. i tried to add siblings() method but still its not working like it should i.e parent of nested li should be visible to toggle its child again. Here is the code
    Code JavaScript:
    $(document).ready(function(){
        $("li").has("ul li").click(function(){
            $(this).toggle()
        })
    })
    Code HTML4Strict:
    <ul>
    <li>Home</li>
    <li>About</li>
        <li>Folio
        <ul>
            <li>Photograph</li>
        </ul>
        </li>
    </ul>
    All those who wander aren't lost.

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume what you are saying is that if you click on Folio you want to toggle the <UL> but keep Folio visible.

    In which case you need

    Code JavaScript:
    $(this).find("ul").toggle()

  3. #3
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ah, thanks a ton!
    All those who wander aren't lost.


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
  •