儿童的简单jQuery Toggle [英] Simple jQuery Toggle of children

查看:82
本文介绍了儿童的简单jQuery Toggle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,为什么不起作用?尝试与此切换ul:

Um, why no worky? Trying to toggle a ul with this:

 $("#others").children(".btn").click(function(){
    if ($(this).children("ul").is(":hidden"))
    {
   $(this).children("ul").slideDown();
    } else {
   $(this).children("ul").slideUp();
    }
 });

并且:

<div id="other">
 <div id="galleries">
  <a href="#" class="btn">Galleries >> </a>
  <ul id="select_gallery">
  ...
  </ul>
 </div>
 <div id="events">
  <a href="#" class="btn">Events >> </a>
  <ul id="select_event">
  ...
  </ul>
 </div>
</div>

推荐答案

UL不是.btn的子代,请尝试使用next:

The UL isn't a child of the .btn its a sibling, try using next:

$("#other a.btn").click(function(){
    var ul = $(this).next("ul");
    if (ul.is(":hidden")) {
        ul.slideDown();
    } else {
        ul.slideUp();
    }
});

这篇关于儿童的简单jQuery Toggle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆