Joshua Payne
Joshua Payne

Reputation: 33

stop it scrolling to the top of the page

i have this bit of code, it limits the Li's to 15 of them and there is a button what shows 15 more Li's but it scrolls the page to the top what i don't want i can't stop it. can you help?

    $(window).load(function(){
    var vis = 15;

    $('li').slice(vis).hide();
    var $more = $('<a href="#">test</a>')
        $more.click(function () {
        $('li:hidden').slice(0, vis).show();        

    if($('li:hidden').length == 0)
        $more.hide();
    });
    $('ul').after($more);});

Upvotes: 0

Views: 85

Answers (1)

slash197
slash197

Reputation: 9034

This should do it

$(window).load(function(){
    var vis = 15;

    $('li').slice(vis).hide();
    var $more = $('<a href="#">test</a>')
        $more.click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        $('li:hidden').slice(0, vis).show();        

    if($('li:hidden').length == 0)
        $more.hide();
    });
    $('ul').after($more);});

Upvotes: 4

Related Questions