Edson
Edson

Reputation: 285

Constructed string for style value not working

function tickleTux() {

var tuxImg = document.getElementById('tux');

tuxImg.style.transition = "transform .5s";

tuxImg.addEventListener('click', itTickles, false);

function itTickles() {

    var addRotation = 10;

    var rotationValue = '"' + 'rotate' + '(' + addRotation + 'deg' + ')' + '"' 

    tuxImg.style.transform = rotationValue;

     console.log(rotationValue);  
}

Basically, this adds a rotation style to an img and makes it rotate.

I just want to know why adding the value to the transform property in this way doesn't work. Why?

The console.log command prints out: "rotate(10deg)"

So what's stopping it from functioning? Some kind of rule?

Thanks for your help.

Upvotes: 0

Views: 18

Answers (1)

Barmar
Barmar

Reputation: 781974

The value shouldn't contain " around it.

var rotationValue = 'rotate(' + addRotation + 'deg)';

Upvotes: 1

Related Questions