jquery - jquery单击内容时如何从内容中删除类
问题描述
text-danger
单击图标时,我想从心形图标中删除该类,但我没有成功:
$(document).ready(function(){
$('.blog-like-counter').on('click', function (e) {
e.preventDefault();
$(this).next('.heart-icon').removeClass('text-danger'); // remove red color heart icon
});
});
<div class="blog-like-counter">
<p class="heart-icon text-danger">♥</p>
</div>
解决方案
请使用 find 方法,因为下一个方法是获取下一个元素而不是内部元素
$('.blog-like-counter').on('click', function (e) {
e.preventDefault();
$(this).find('.heart-icon').removeClass('text-danger'); // remove red color heart icon
});
推荐阅读
- jquery - Jquery 和 Bootstrap 4 - 用于调整大小和滚动顶部的导航栏转换
- r - ggplot 将截止 abline 添加到堆叠的条形图,其中条件:达到阈值
- cassandra - cassandra 节点上的数据大小不均匀
- javascript - 更改 formlyConfig 以允许重新选择一个空选项
- php - centos上的500内部服务器错误
- spring - 转换单声道
- > 到通量
在春天 5 - java - java.io.IOException:流在 PDFbox setValue 循环期间关闭
- batch-file - 使用批处理文件运行 ant 命令
- mysql - 如何获取一段时间内创建第一个数据的用户的数据?
- postman - Postman - 在另一个测试中使用来自一个测试的部分响应数据