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
  • 37,241
  • 25
  • 195
  • 267
Gautam Menariya
  • 546
  • 2
  • 7
  • 27
  • 1
    `:last` <- surely this will only make the script trigger of the last element -> am I missing something (your question is not well worded so I might be getting confused :-P) – GrahamTheDev Apr 04 '14 at 17:27
  • 1
    http://learn.jquery.com/events/event-delegation/ – Blazemonger Apr 04 '14 at 17:27
  • 1
    possible duplicate of [In jQuery, how to attach events to dynamic html elements?](http://stackoverflow.com/questions/1359018/in-jquery-how-to-attach-events-to-dynamic-html-elements) – Blazemonger Apr 04 '14 at 17:28
  • :last not give last id of loaded divs. http://rippleclever.in/ is demo link so uyou understand. @GrahamRitchie – Gautam Menariya Apr 04 '14 at 17:33

1 Answers1

0

You should use this:

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