Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery删除上的类。单击_Jquery - Fatal编程技术网

jQuery删除上的类。单击

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

这是我的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?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')