I want an animation such that it toggles to slide the div left and right every time I click button. However, when I actually use the code it only slides it to right once and stops working any more.
<script>
var left = 1;
$(document).ready(function(){
$("button").click(function(){
if(left==1){
$("div").animate({left:'250px'});
left=2;
}else{
$("div").animate({right:'250px'});
left=1;
}
});
});
</script>
What's wrong with this code? I couldn't think of a problem.