font awesome 5(svg):jquery toggleclass不工作

ssm49v7z  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(168)

我无法在字体元素上切换类。我们该怎么做呢?元素被转换为元素。我只能切换一次类,然后它就不工作了。代码如下:https://codepen.io/overdrivemachines/pen/jomaggk

<div class="container">
  <div class="post-actions">
    <i class="fa fa-heart like-32 fa-2x post-like active" data-id="32"></i>
  </div>
  <div class="post-actions">
    <i class="fa fa-heart like-33 fa-2x post-like" data-id="33"></i>
  </div>
  <div class="post-actions">
    <i class="fa fa-heart like-34 fa-2x post-like" data-id="34"></i>
  </div>
</div>
.post-actions {
  margin: 20px;
  background: #fee; 
  i, svg {
    color: #ddd;
    cursor: pointer;
    margin-right: 10px;
  }
  i:hover, svg:hover {
    color: #999;
  }
  i.active, svg.active {
    color: red;
  }
}
$(function () {
  $(".post-like").on("click", function () {
    var post_id = $(this).data("id");
    console.log(post_id);
    $(this).toggleClass("active");   
  });  
});

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题