Toggle font awesome class on button click

后端 未结 7 611
心在旅途
心在旅途 2020-12-31 22:37

I have the code as here in this jsfiddle, I want the font awesome icon to change on button click using javascript, but it does\'nt seem to work. I\'m new to javascript so pl

相关标签:
7条回答
  • 2020-12-31 23:32

    You can use only Javascript:

     function fav() {
        var icon = document.getElementById("favIcon");
          if (icon.classList.contains("fa-star-o")) {
            icon.classList.remove("fa-star-o");
            icon.classList.add("fa-star");
        } else {
           icon.classList.remove("fa-star");
           icon.classList.add("fa-star-o");
        }
     }
    

    example

    0 讨论(0)
提交回复
热议问题