Expand and collapse a div

Posted by user494118 on Stack Overflow See other posts from Stack Overflow or by user494118
Published on 2011-01-02T12:42:00Z Indexed on 2011/01/02 12:53 UTC
Read the original article Hit count: 291

I have a list of itens and they are holding images, each image is 800w x 600 H. The original div height is 800 W x 300 H, I figured out how to expand the div when it is clicked, but i want to know how to collapse it when you click it while it is already expanded. right now it just expands the div even farther

  $('.expand').bind('click', function() {
  var currHeight = $(this).css('height').replace(/px/,'');
  currHeight = currHeight * 1;
  var newHeight = currHeight + 500;
  $(this).animate({
     height: newHeight
  },1000);

 });

any idea on how to create an if else statement that would say, IF the div is already expanded then collapse on click, or if the div is not expanded, expand to # of px.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery