Skip to content

Instantly share code, notes, and snippets.

@jessehintze
Created June 8, 2018 21:33
Show Gist options
  • Save jessehintze/f5c3567679581e8a7b2925806597e214 to your computer and use it in GitHub Desktop.
Save jessehintze/f5c3567679581e8a7b2925806597e214 to your computer and use it in GitHub Desktop.
Show More
$('.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 &#9660;</span><span id="showLess">See Less &#9650;</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