我有一个页面,比如 5 个帖子,全部在#article
. 以下是用于切换隐藏/显示的 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 个帖子都会展开。
如何修改我的代码以仅扩展该特定帖子?