我有一个单页,有5个帖子,全部在#article
。以下是jQuery代码用来切换隐藏/显示:在多个DIV中使用jquery显示/隐藏内容
$(".click-show-more").click(function() {
if($(".content").hasClass("show-more")) {
$(this).text("(Show Less)");
} else {
$(this).text("(Show More)");
}
$(".content").toggleClass("show-more");
});
的HTML
结构为:
<div class="article">
<div class="content show-more">Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here.
Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here. Some text here.
</div>
<div class="click-show-more">(Show More)</div>
</div>
现在,我有这样的结构,在一个页面上5-6次,每当我点击Show More
,所有5-6个帖子都展开。
如何修改我的代码以仅展开特定帖子?
没有用。仍然是同样的事情。 –
这是因为您需要将切换更改为正确的div。 – jcsanyi
@PalakArora ..检查编辑 –