我有一個單頁,有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 ..檢查編輯 –