css – How to change bootstrap icon’s attributes using javascript

0
81
html - Animation after toggling doesn't apply the second style


document.addEventListener('DOMContentLoaded', function () {
      var heart = document.createElement('i')
      heart.className="bi bi-heart"
      document.querySelector('#posts').append(heart)
      heart.onclick = function () {
        this.className="bi bi-heart-fill"
        this.setAttribute('fill', 'red')
      }
    } )
<head><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css"></head>
<body><div id="posts"></div></body>



Source link

Leave a reply

Please enter your comment!
Please enter your name here