문제

I am trying to put a listener to a scrollable div that looks like this:

$(document).ready(function() {
        $scroll = $('.generic-table')
        $scroll.scroll(function() {
           // if($(window).scrollTop() + $(window).height() == $(document).height()) {
               alert("bottom!");
           // }
        });
});

The problem is that this Div is not part of the original template but it is added to the template AFTER the user takes a specific action.

If the Div was loaded in the beginning of the page, it would work.

How to overcome that kind of issue?

도움이 되었습니까?

해결책

You cannot use event delegation for .scroll() as @marcelosalloum rightly pointed out in the comments. You have to write the handler when you actually create the element.

//Create .generic-table here. BEGIN
Code
//Create .generic-table here. END

//Handle event immediately.
$('.generic-table').scroll(function() {
    alert("bottom!");
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top