Created
June 23, 2014 06:56
-
-
Save gmaggio/da09a976d02afd72e835 to your computer and use it in GitHub Desktop.
[jQuery] Hide & show list items after nth item
This file contains 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
$(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