I need -
- To create a bootstrap icon (heart) when DOM content is loaded
- When the icon is clicked, the heart icon fills with red (Here I use heart-fill icon)
- Both of the icons to be larger than the original
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/bootstrap-icons@1.5.0/font/bootstrap-icons.css"></head>
<body><div id="posts"></div></body>
When I click the heart, it fills with black, not red. I also do not know how to make it larger by increasing the value of width and height. I saw other questions related to this, but none of them solve my problem.