Show More / Less

Show More / Less

Trying to expand / contract the contents of a div using show more / less.  When I select 'more' the list expands and the action link is now set to 'less.'.  When I select 'less', again, the list contracts as expected , but the action link is not resetting to 'more.'  I can't seem to figure out where I'm going wrong....

  1. $(document).ready(function() {
  2.     $('#refinements div').each(function(){
  3.         var hiddenElements = $(this).children('p:gt(10)').hide();
  4.         if (hiddenElements.size() > 0) {
  5.             var showCaption = 'more';
  6.             $(this).children('p:gt(10)').hide();
  7.             $(this).after('<a style="color:red;" href="#" class="more">' + showCaption + '</a>');
  8.         }
  9.     });
  10.   
  11.     $('.more').click(function(e){
  12.         e.preventDefault();
  13. $(this).prev('div').children('p:gt(10)').slideToggle();
  14.         $(this).text('less');
  15.     },
  16.     function() {
  17.         hiddenElements.hide();
  18.         $(this).text(showCaption);
  19.     }); 
  20. });