I am trying to rotate a span created using JavaScript on a button click, the class gets added to the span but the rotate doesn't effect the span.
<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>