jQuery().ready(function() { $('.methods').each(function() { var height = $(this).height(); $(this).addClass('closed').css({ height: $(this).children('.name').height() + 2 }); $(this).children('.name').css({ cursor: 'pointer' }).click(function() { if($(this).parent().hasClass('closed')) { $(this).parent().removeClass('closed').addClass('opened').stop().animate({ height: height }, 200); } else { $(this).parent().removeClass('opened').addClass('closed').stop().animate({ height: $(this).height() + 2 }, 200); } }); }); });