I am having an issue with toggling a class name in my code. I have a class named (bi bi-clipboard) and I want to change it to (bi-clipboard-check) when it is clicked. However, the problem is that the new class name gets added next to the existing one like this:
Before clicking:
<i class="bi bi-clipboard" onclick="changeIcon(this)"></i>
After clicking:
<i class="bi bi-clipboard bi-clipboard-check" onclick="changeIcon(this)"></i>
Here is the method I am using:
function changeIcon(icon){
icon.classList.toggle("bi-clipboard-check");
}
I noticed another example using fontawesome where the class toggles properly using the toggle() JavaScript method. In my case, however, the classes are not toggling correctly as they are just getting added next to each other. Any solutions or suggestions would be greatly appreciated.