0

I have img and I need to rotate it 90 degree when I click on it.

<img src="img/right-arrow.png" alt="" class="show">

when I use

.show {
transform: rotate(90deg); 
}

in Css file it works. but when I do it in jQuery it doesn't work. here is my code in jQuery

$('.show').click(function(){
    $(this).css("-webkit-transform" : "rotate(90deg)");
}
);

4 Answers 4

1

This is because you used a : in your function, use a comma instead:

$(this).css("-webkit-transform", "rotate(90deg)");
Sign up to request clarification or add additional context in comments.

Comments

1

see here jsfiddle

if you want to use : in your css in JQ you need to put the whole code between {}

like so :

$('.show').click(function(){
    $(this).css({"-webkit-transform" : "rotate(90deg)"});
}
);

OR if you don't want to use {} use , instead of : like so

$('.show').click(function(){
    $(this).css("-webkit-transform" , "rotate(90deg)");
}
);

Comments

0

Try this

$('.show').click(function(){
  $(this).css({
    '-moz-transform':'rotate(90deg)',
    '-webkit-transform':'rotate(90deg)',
    '-o-transform':'rotate(90deg)',
    '-ms-transform':'rotate(90deg)',
    'transform':'rotate(90deg)'
  });
});

Comments

0

try this one:

$('.show').click(function(){
    $(this).css({"-webkit-transform" : "rotate(90deg)"});
}
);

DEMO HERE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.