jQuery删除上的类。单击
这是我的html:jQuery删除上的类。单击,jquery,Jquery,这是我的html: <a href="#">Read more</a> <div class="moreDetails"> <p class="additionalText">Some text help here, random length.</p> <p class="author"> <span class="bolder"><a href="minidashboard.php?u
<a href="#">Read more</a>
<div class="moreDetails">
<p class="additionalText">Some text help here, random length.</p>
<p class="author">
<span class="bolder"><a href="minidashboard.php?user_url=http://url.people/1332517">Name</a>
</span>
</p>
<div class="replies">
<span>
<a href="topic.php?id=http://url/topics/1049198">1</a>
</span>
</div>
我现在想要的是,当单击
时,类.trim
将被删除并显示内容
.trim
将段落设置为固定高度,并将溢出设置为隐藏。您可以为该链接设置一个类,如下所示:
<a class="readMore" href="#">Read more</a>
$("a.readMore").click(function() {
$(this).next().find('.additionalText').removeClass('trim');
});
这是通过查找与
和相关的
来实现的。如果
没有立即跟随而不是。则可以为该链接设置一个类,如下所示:
<a class="readMore" href="#">Read more</a>
$("a.readMore").click(function() {
$(this).next().find('.additionalText').removeClass('trim');
});
这是通过查找与和相关的
来实现的。如果
没有立即跟随而不是。仅供参考,我不是说您的代码不工作,而是说.filter()
的使用有点奇怪。您可能想改用.each()
。或者使用.filter()
执行类似的操作:$('.moreDetails p.additionalText').filter(函数(){return$(this.text().length>32;}).addClass('trim')代码>仅供参考,我不是说你的代码不工作,而是说.filter()
的使用有点奇怪。您可能想改用.each()
。或者使用.filter()
执行类似的操作:$('.moreDetails p.additionalText').filter(函数(){return$(this.text().length>32;}).addClass('trim')代码>