-1

Class jquery hover function are working after scroll.

$(document).ready(function() {
    $('img').hover(function(){
        alert('hello');
    },function(){
        alert('hello not');
    });
});

on hovering images loaded on first site are showing alert hello but after scroll images load(lazzy loading). On hovering those images alert is not showing.

user1837779
  • 575
  • 1
  • 5
  • 17

2 Answers2

3

This should work after loading new images

$(document).ready(function() {

    $("body").on("mouseenter", "img", function(){
        alert('hello');
    });

    $("body").on("mouseleave", "img", function(){
        alert('hello not');
    });

});
Chop
  • 509
  • 2
  • 7
1

You need delegation:

$(document).ready(function() {
    $(document).hover('img', function(){
        alert('hello');
    },function(){
        alert('hello not');
    });
});
Community
  • 1
  • 1
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474