I have a div, when you click it I want it to rotate and then when you click it again it rotates back, a toggle. I’m doing this with CSS transforms, and I need to add the classes also with jquery. I have the classes stored in vars and then am trying to apply them. Here is the jfiddle I’m working on, thanks for your help in advance.
here is the code:
<div id="beffects_of_yoga_info" style="width:50px;height:50px;background:red;"></div>
jquery:
$(document).ready(function() {
var css_info_timing = {
"-webkit-transform": "all 1s ease;"
}
var css_info_rotate = {
"-webkit-transition": "rotate(150deg)"
}
$("#effects_of_yoga_info").css(css_info_timing);
$("#effects_of_yoga_info").click(function () {
$("#effects_of_yoga_info").toggleClass(css_info_rotate);
});
});
Here you’re using
toggleClass, but you’re actually trying to toggle a property!First of all, add this css class:
Then this jQuery listener:
Check the demo
Edit
As you don’t have access to CSS, use this code to add the rule dinamically:
Another demo