我有serval鏈接按鈕爲了顯示它下面的div。如何點擊鏈接時選擇同胞元素?
<a class="btnComment" onclick="showComment()" isshow='0'>{{ post_comments.count }} comment</a>
<div class="comment">
....
</div>
<a class="btnComment" onclick="showComment()" isshow='0'>{{ post_comments.count }} comment</a>
<div class="comment">
....
</div>
<a class="btnComment" onclick="showComment()" isshow='0'>{{ post_comments.count }} comment</a>
<div class="comment">
....
</div>
我想碰一個linkbutton,只顯示它下面的div元素。但我的js代碼:
function showComment(){
var isshow=$(this).attr('isshow');
if(isshow=="0"){
this.$(".comment").show();
$(this).attr('isshow',"1");
}
else{
this.$(".comment").hide();
$(this).attr("isshow","0");
}
}
此顯示所有div。當我使用$(this).siblings()或$(this).next()時,我得到了null,我不知道爲什麼不起作用。
我該怎麼辦?
請上傳您的代碼到http://www.jsFiddle.net – Itay