我有一个带有回复选项的评论列表。单击回复按钮时,评论下方应出现一个表单。
HTML:
<div id="" class="comment">
<div class="comment-message">Message
<div class="information">
<a id="" class="comment-reply" href="/comments/reply/"> Reply </a>
</div>
</div>
</div>
<div class="test">Test</div>
CSS:
.test{display:none;}
jQuery:
$('.comment-reply').live("click", function(e) {
e.preventDefault();
$this = $(this);
$this.closest('.test').toggle();
});
我尝试使用以下方法:
$this.closest('.test').toggle();
对此的任何帮助将不胜感激,谢谢。
最佳答案
如果您的 html 结构相同,那么您可以尝试以下,
$(this).closest('.comment').next().toggle()
如果 Reply
部分和 test
之间有一些元素,则使用 .nextAll
$(this).closest('.comment').nextAll('.test').toggle()
关于jquery - 查找类的最接近的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12586822/