Skip to content

Instantly share code, notes, and snippets.

@gmaggio
Created June 23, 2014 06:56
Show Gist options
  • Save gmaggio/da09a976d02afd72e835 to your computer and use it in GitHub Desktop.
Save gmaggio/da09a976d02afd72e835 to your computer and use it in GitHub Desktop.
[jQuery] Hide & show list items after nth item
$(document).ready(function(){
// Source: http://stackoverflow.com/a/7973317/851045
$('ul.sub-category').each(function(){
var max = 3
if ($(this).find("li").length > max+1) {
$(this)
.find('li:gt('+max+')')
.hide()
.end()
.append(
$('<li class="more">Lihat selebihnya...</li>').click( function(){
$(this).siblings(':hidden').show().end().remove();
})
);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment