I am attempting to spin a span generated using JavaScript when a button is clicked. The class is added to the span, but the spinning effect does not apply.
<p>Click the button to create a SPAN element.</p>
<button onclick="myFunction()">Try it</button>
<button onclick="myFunction2()">Spin Span</button>
<script>
function myFunction() {
var x = document.createElement("SPAN");
var t = document.createTextNode("This is a span element.");
x.appendChild(t);
document.body.appendChild(x);
x.setAttribute("id","firstPracPara");
}
function myFunction2() {
var element = document.getElementById("firstPracPara");
element.classList.add("rotate");
}
</script>
<style>
.rotate{
transform: rotate(20deg);
}
</style>