0

I'm trying to add a font-awesome icon to a button element but I can't figure out how to do it properly.
textContent overwrite the existing text and .createTextNode adding it as a raw text rather than an element.

const rockChosen = document.getElementById('rock');
const icon = document.createTextNode('<i class="fa-solid fa-robot"></i>');
rockChosen.appendChild(icon);
<button id="rock">
  Rock
  <i class="fa-solid fa-hand-back-fist"></i>
</button>

Any help would be appreciated!

  • Use this script to set the icon: document.querySelector("#rock i").className = "fa-solid fa-robot"; – Yogi Oct 14 '22 at 16:01

0 Answers0