My code is like this :
$(document).ready(function () {
    size_li = $("#myList li").length();
    x=3;
    $('#myList li:lt('+x+')').show();
    $('#loadMore').click(function () {
        x= (x+5 <= size_li) ? x+5 : size_li;
        $('#myList li:lt('+x+')').show();
    });
    $('#showLess').click(function () {
        x=(x-5<0) ? 3 : x-5;
        $('#myList li').not(':lt('+x+')').hide();
    });
});
Or see demo and full code here : http://jsfiddle.net/oscar11/6FzSb/4177/
I use jquery 3.0.1
When executed, there exist error :
TypeError: $(...).length is not a function
How can I solve it?
Instead of this
$("#myList li").length();
Use this:
$("#myList li").length;
The $("#myList li") returns an array like object. All array like objects have a property called length, which when be read returns the number of items contained in the array like object. That being said there isn't any function called length. Hence length() is meaningless.
length is a property, not a function, so remove the ()
$("#myList li").length;
                        length is not a function it is just Yourthings.length without ().
more doc at length documentation  
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With