<div class="post-content">
<p>Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text </p>
<p>More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text </p>
<span class="more">more/less</span>
</div>
$('.post-content p:not(:first-child)').css('display', 'none');
$(".more").click(function () {
$('.post-content p:not(:first-child)').css('display', 'block');
});
问题很明显。我需要制作一个toogle效果,以便在第一段之后隐藏所有p
。
答案 0 :(得分:2)
改为使用hide
和toggle
:
// cache elements so you don't repeatedly query the DOM
toggleParas = $('.post-content p:not(:first-child)');
toggleParas.hide();
$(".more").click(function () {
toggleParas.toggle();
});
答案 1 :(得分:1)
$('.post-content p:eq(1)').hide();
$(".more").click(function () {
$(this).prev('p').slideToggle();
});