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....
- $(document).ready(function() {
- $('#refinements div').each(function(){
- var hiddenElements = $(this).children('p:gt(10)').hide();
- if (hiddenElements.size() > 0) {
- var showCaption = 'more';
- $(this).children('p:gt(10)').hide();
- $(this).after('<a style="color:red;" href="#" class="more">' + showCaption + '</a>');
- }
- });
-
- $('.more').click(function(e){
- e.preventDefault();
- $(this).prev('div').children('p:gt(10)').slideToggle();
- $(this).text('less');
- },
- function() {
- hiddenElements.hide();
- $(this).text(showCaption);
- });
- });