I want to change my css style by JavaScript like i change transform: rotateZ(120deg);
<script>
var Rotate = ['90deg','120deg','150deg','180deg','210deg','240deg','90deg','120deg','150deg','180deg','210deg','240deg'];
function Time() {
var marg, d, hour;
marg = document.getElementById("hand");
d = new Date();
hour = d.getHours();
for(i = 0; i < 12; i++) {
if(hour == i) {
var x=Rotate[i];
alert(x);
marg.style.transform= "rotateZ(x)";
}
}
}
</script>
alert(x) is working but transform is not working. Is there any way to use array list to change transform value?
marg.style.transform= "rotateZ(" + x + ")""rotateZ(x)"is just a string -- you were not actually using thexvariable at all!