I'm trying to add a class to
<span id="sp1">
using:
document.getElementById("sp1").classList.add("fa fa-hand-rock-o");
But it is showing error:
String contains an invalid character
fa fa-hand-rock-o
can not be a single class because class names can not have space(s).
Here I assume you are trying to add two different classes. When adding multiple classes by using classList.add()
specify all the classes as individual comma separated string like:
.add("fa", "fa-hand-rock-o")
Code Example:
document.getElementById("sp1").classList.add("fa","fa-hand-rock-o");
console.log(document.getElementById("sp1"));
<span id="sp1">Test Container</span >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With