jQuery选择一个父母的孩子 [英] Jquery selecting a parents child

查看:75
本文介绍了jQuery选择一个父母的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问特定div(容器" div中的内容" div)的父OF的子对象以在Jquery中进行动画处理.目前我正在使用...

I am trying to access the child OF the parent OF a specific div (the "content" div within the "container" div) to animate in Jquery. Currently i am using...

<script> 
$(document).ready(function(){
  $(".container").click(function(){
    $(this).find('.item').slideToggle("slow");
  });
});
</script>

...因此,当您单击容器时,内容" div将切换扩展和收缩. 但是,我真正想要的是单击单击ME" div来展开另一个div,这样当您在内容上的任何位置单击时,内容都不会再次收缩!

...so that when you click on the container, the "content" div will toggle expanding and shrinking. However, what i would really like is to click on the "click ME" div to expand the other div, so that when you click anywhere on the content, the content does not shrink again!

选择父div的子代将非常方便.我假设选择器可能是类似以下内容的东西:

It would be VERY convenient to select the child of the parent div. I am presuming that the selector may be something along the lines of:

    $(this).parent.find('.item').slideToggle("slow");

但是我真的不知道!

有人有建议吗?

推荐答案

尝试一下:

$(this).closest('your parent').find('.item').slideToggle("slow");

parent是一种方法,因此$(this).parent().find('.item')更有意义.

parent is a method so $(this).parent().find('.item') makes more sense.

如果.item.container的兄弟姐妹,那么您可以执行$(this).siblings('.find').slideToggle("slow")

If .item is a sibling of .container then you can just do $(this).siblings('.find').slideToggle("slow")

  • .closest()
  • .siblings()

这篇关于jQuery选择一个父母的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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