0

i wanted to get the scroll method and load somthing while scrolling happens . its not working properly maybe because my elements are being added to the page dynamically. however i see the existance of the elements but its not working programmatically. and while i add these methods into my chrome's console then it start to work. idk how to solve it.

        

    $(document).ready(function () {
                ////First Method
                $(".convHistory").on('scroll', function () {
            console.log('Event Fired');
        });
        
        ////Second Method
        $(".convHistory").bind('scroll', function () {
                console.log('Event worked');
                }); 

        
        ////Third Method
        document.addEventListener('scroll', function (event) {
            if (event.target.className.includes("convHistory")) {  
                console.log('scrolling', event.target);
            }
        }, true /*Capture event*/);
        
        


                //forth method
        $('.convHistory').scroll(function () {
            console.log('Event worked');

        });
        
        
        
        


    });
Mamadmti
  • 61
  • 6

2 Answers2

0

As your elements are dynamic, bind events for dynamic elements like this:-

$(document).on('scroll', '.convHistory', function () {
     console.log('Event worked');
});
Developer
  • 1,297
  • 1
  • 4
  • 15
0

As you already said, the elements are binding dynamically, you have to do something like below

div.append(yourElement class="convHistory");

then after that

$(".convHistory").on('scroll', function () {
    console.log('Event Fired');
});
Ibrahim shaikh
  • 235
  • 2
  • 15