我有一个带有回复选项的评论列表。单击回复按钮时,表单应显示在注释下方。
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();
对此有任何帮助将非常感谢,谢谢。
答案 0 :(得分:3)
如果您的html结构相同,那么您可以在下面尝试,
$(this).closest('.comment').next().toggle()
如果Reply
部分与test
之间存在某些元素,请使用.nextAll
$(this).closest('.comment').nextAll('.test').toggle()
答案 1 :(得分:1)
试试这个:
如果您有其他最接近的元素而不仅仅是类.test
的注释,则需要确保获取正确的元素执行以下操作:
$(this).closest('.comment').next('.test').toggle();