Jquery 如何获取下一个非子元素

Jquery 如何获取下一个非子元素,jquery,jquery-selectors,Jquery,Jquery Selectors,老实说,我在发帖前尝试过搜索,但找不到具体的东西。 所以我的任务是当用户点击链接时,在博客中显示隐藏的内容。 HTML如下所示: <div class="entry"> <p>Here is a visible content <a class="a-toggle"> Read More...</a></p> <div class="hidden_post"><p>Here is all the hidden c

老实说,我在发帖前尝试过搜索,但找不到具体的东西。 所以我的任务是当用户点击链接时,在博客中显示隐藏的内容。 HTML如下所示:

<div class="entry">
<p>Here is a visible content <a class="a-toggle"> Read More...</a></p>
<div class="hidden_post"><p>Here is all the hidden content</p></div>
</div>

所以,为了获得下一个元素,我需要先转到父元素,然后从那里继续搜索。 现在对我来说更复杂了,因为我实际上会有几个隐藏的 一个“条目”中的内容。像这样:

<div class="entry">  
<p>Here is a visible content <a class="a-toggle"> Read More...</a></p>
<div class="hidden_post"><p>Here is hidden content #1</p></div>
<p>Here is a visible content <a class="a-toggle"> Read More...</a></p>
<div class="hidden_post"><p>Here is hidden content #2</p></div>
<p>Here is a visible content <a class="a-toggle"> Read More...</a></p>
<div class="hidden_post"><p>Here is hidden content #3</p></div>
</div>

这里是一个可见的内容阅读更多

这里是隐藏内容#1

这里是一个可见的内容阅读更多

这里是隐藏内容#2

这里是一个可见的内容阅读更多

这里是隐藏内容#3

现在如果我使用
$(this).parent().next(.hidden_post”).slideDown(“slow”)
它将进入“入口”分区,然后只找到第一个“隐藏的帖子”。我猜
我仍然需要另一个解决方案,直接从
转到它旁边的
。有什么解决办法吗?

您可以使用:


在这种情况下,最快的方法是执行parent->next

$(".a-toggle").click(function(){
 $(this).parent().next(".hidden_post").slideDown("slow");
});

可以使用children方法获取父元素的所有直接子元素

$('div.entry').children('div.hidden_post');

这将返回具有entry类且具有hidden_post类的div的所有div子级。

Thanx Jacob,仍然存在一些问题,我在下面的回答中描述了这些问题。Thanx TJB,仍然存在一些问题,我在下面的回答中描述了这些问题。
$(".a-toggle").click(function(){
 $(this).parent().next(".hidden_post").slideDown("slow");
});
$('div.entry').children('div.hidden_post');