Say I need an element to animate when clicked. To do this I just:
$('#header .icon').click(function() {
$('#header form').animate({width:'195px'});
});
But how would I make it so that when I click the element again the opposite animate takes place? (e.g. animate to width: 0px; )
You can use
.toggle()like this:If it was initially out you could toggle it’s width like this: