scroll() in not working in jQuery for dynamic elements

jquery, scroll

Solution

Browsers change, jQuery bugs are fixed, that's two reasons why it's important to always use a recent version of jQuery (after due tests, you can't just point to latest).

Your code, adapted to jQuery 1.9, would be, for another event type,

$(document).on("event_type",".wrapper1", function(){
    $(".wrapper2")
        .scrollLeft($(".wrapper1").scrollLeft());
});

The reason to use `$(document)` as receiver and not `$(".wrapper1")` is that only the elements existing at binding time would receive and delegate the events. `on` doesn't work like the old `live`.

Except that this won't work for `scroll` events as they don't bubble.

So the most reasonnable solution I can propose would be to define a function :

$.fn.bindScrollHandler1 = function(){
    $(this).on('scroll', function(){
       $(".wrapper2").scrollLeft($(".wrapper1").scrollLeft());
    });
}

and call it at start :

$('.wrapper1').bindScrollHandler1();

and each time you create a new .wrapper1 element :

myNewElement.bindScrollHandler1();

Demonstration

Note that your complete logic seems a little lacking, as you don't pair the scrollbars but make them all work the same.

Problem

I am using the following.This is not working for dynamically created elements.I am usinh jQuery 1.4.2 ``` $(".wrapper1").live("scroll",function(){ alert(123); $(".wrapper2") .scrollLeft($(".wrapper1").scrollLeft()); }); ``` This is also not working for normal elements also.(Which are loaded while the page loading) What might be the reason here .Please help me.Thanks in advance....

Original source