Created
June 8, 2018 21:33
-
-
Save jessehintze/f5c3567679581e8a7b2925806597e214 to your computer and use it in GitHub Desktop.
Show More
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.hide-show').each(function () { | |
var thisList = $(this); | |
var thisListItems = thisList.find('li'); | |
var size_li = thisListItems.length; | |
if(size_li > 5) | |
{ | |
thisList.after('<div class="hide-show-buttons"><span id="showMore">See All ▼</span><span id="showLess">See Less ▲</span></div>'); | |
} | |
var x = 5; | |
thisList.find('li:lt('+x+')').show(); | |
}); | |
$('body').on('click', '#showMore', function () { | |
var this_size_li = $(this).parent().parent().find('li').size(); | |
var x = this_size_li; | |
$(this).parent().parent().find('li:lt('+x+')').show(); | |
$(this).parent().parent().find('#showLess').show(); | |
if(x >= this_size_li){ | |
$(this).parent().parent().find('#showMore').hide(); | |
} | |
}); | |
$('body').on('click', '#showLess', function () { | |
var this_size_li = $(this).parent().parent().find('li').size(); | |
var x = 5; | |
$(this).parent().parent().find('li').not(':lt('+x+')').hide(); | |
if(x <= 5){ | |
$(this).parent().parent().find('#showLess').hide(); | |
} | |
if(x < this_size_li){ | |
$(this).parent().parent().find('#showMore').show(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment