0

I am creating a web page where I load data with ajax.

HTML

<div class="containerHome scrollNew"> 
    <div class="single loop_a1" id="{SLUG}">
    </div> 
</div>

JAVASCRIPT

$('.homeLeftContainer .single:last').bind('enterviewport', myHandler).bind('leaveviewport', myHandler).bullseye();
        function myHandler(e) {
            var last_slug_a1 = $(".homeLeftContainer .single:last").attr("id"); //Last article Slug
            //alert(last_slug_a1);
            $('div#last_msg_loader').html('<img src="img/loader.gif">'); 
            $.post("modules/frontend/ajax/load_data.php?action=get&last_msg_id="+last_slug_a1, 
            function(data){
                if (data != "") {
                    $(".homeLeftContainer .single:last").after(data);           
                }
                $('div#last_msg_loader').empty();
            });
        } 

This code is working fine. It put data when .single div is enter the screen or leave the screen. Problem with this code is it not take var last_slug_a1 value dynamically. ajax page only trigger when perticular div(4th) show or leave the viewport.

I trie $(window).scroll function but it show weared result. Can you please tell me how to correct this?

Cœur
  • 34,719
  • 24
  • 185
  • 251
Gautam Menariya
  • 514
  • 2
  • 5
  • 24

1 Answers1

0

You should use this:

$(document).on("click","#selector",function(){
    //should be okay now
});
dian
  • 36
  • 4