Having an issue with using toggleClass
in jQuery.
Check out the code snippet below:
$(".guzik").click(function() {
$("#third").toggleClass('.pillar-animation-two');
});
function test(){
document.getElementById('third').className('.pillar-animation-two');
}
.pillar {
width:50px;
height:10px;
background-color:red;
margin-top:5px;
}
.pillar:nth-child(1) {
margin-top:0;
}
.pillar-animation-one {
transform:rotate (10deg);
}
.pillar-animation-two {
transform:rotate (20deg);
width:10px;
height:10px;
background-color:red;
margin-top:5px;
}
.pillar-animation-three {
animation-name:three;
animation-duration:1s;
}
@keyframes three {
0%{transform:rotate(0deg);}
100%{transform:rotate(40deg);}
}
.button {
margin-top:10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="hamburger">
<div class="pillar"></div>
<div class="pillar"></div>
<div class="pillar" id="third"></div>
</div>
<button class="button" type="button" onclick="test()"> Click me !</button>
Any ideas about what I might be doing wrong? Even addClass
isn't working, so feeling quite lost here. Tried creating a JS function but that's not helping either.
Please point out where the mistake might be located.
Thank you.