Search code examples
javascriptjquerydom-traversal

how to check if end of List Items is reached


hey guys i am working on a slider and on up and down arrow keys i am shifting the slides. Now i am unable to do this but how can I check if ok LI's has reached so i can something like scrolling back to top. thanks. here is my code for prev and next

 $(document).keydown(function (e) {
    if (e.keyCode == 40) {

        var next = ul.find('li.current').next();

        if (next.length) {
            next.click();
            ul.find('li.current').removeClass('current');
            next.addClass('current');
        }
    }
});
$("#thumbsList li").click(function () {
    $(this).addClass('currentThumbNail');

    $('#thumbsList li').not(this).removeClass('currentThumbNail');

});

Thanks.


Solution

  • Using an else branch after your if (next.length) { seems good enough to me.

        if (next.length) {
            next.click();
            ul.find('li.current').removeClass('current');
            next.addClass('current');
        }
        else {
            //no more slides found, dammit!
        }