You can use the gt() and lt() selector along with :visible here.
The following 5 results are shown below when you click and delete a link after viewing all the elements.
$('.mydata:gt(4)').hide().last().after( $('<a />').attr('href','#').text('Show more').click(function(){ var a = this; $('.mydata:not(:visible):lt(5)').fadeIn(function(){ if ($('.mydata:not(:visible)').length == 0) $(a).remove(); }); return false; }) );
working example: http://jsfiddle.net/niklasvh/nTv7D/
Regardless of what other people suggest, I would not hide elements with CSS, but instead did it in JS, because if the user has JS disabled and you hide elements with CSS, he will not get them visible. However, if it is disabled by JS, they will never be hidden, and this button will not appear, etc. Therefore, it has a full noscript reserve in place + search engines do not like hidden content (but they will not know its hidden if you do this when loading the DOM).
source share