简体   繁体   中英

JQuery Quickfix : I don't know how to call it

This is my HTML:

  <ul class="test">
   <li><a href="#">One</a>
    <ul>
     <li>Content One</li>
    </ul>
   </li>
   <li><a href="#">Two</a>
    <ul>
     <li>Content Two</li>
    </ul>
   </li>
  </ul>

I want to hide UL.TEST LI UL . When I click anchor "one" or when I click "ul.test li" or "ul.test li a"

How will I do it without using a CLASS or ID in the "ul.test li ul"?

My code is:

  $(function(){
   $("ul.test li").click(function(e){
    e.preventDefault();
    $(this).slideToggle("fast");
   });
  });

What I want to do:

  $(this + "ul").slideToggle("fast");

I want to hide only ul.test li ul only.

what if?

$("ul.test li a").click(function(e){
  $('ul', this).slideToggle("fast");
});

how will I go back to ul.test li using $('ul', this).slideToggle("fast");

how about

$(this).find("ul").slideToggle("fast");

inside your click handler

EDIT:

maybe this will be of more use to you. http://api.jquery.com/category/traversing/tree-traversal/

Try this:

$("ul.test li").click(function(e){
  $('ul', this).slideToggle("fast");
});

Demo: http://jsfiddle.net/9KAhT/

$("ul.test li a").click(function(e){
   $(this).next().slideToggle("fast");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM