Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .delegate() not working on load and changeData events

Tags:

jquery

Can someone enlighten me on the jQuery delegate, what events are handled and what aren't. The follow code doesn't work

$("#browser").delegate( ".photo", {
    "load": function(e) {
        alert("photo loaded");
    }
});

but the following code work

$(".photo").load( function(e) {
    alert("photo loaded");
} );

I also try to delegate changeData event to a class which doesn't work as well

$("#browser").delegate( ".thumbnail", {
    "changeData": function(e, prop, value) {
        alert( prop + " = " + value );
    }
});

but the following code work

$(".thumbnail").bind( "changeData", function(e, prop, value) {
    alert( prop + " = " + value );
}
like image 807
jhloke Avatar asked Mar 13 '11 16:03

jhloke


2 Answers

Not:

$("#browser").delegate( ".photo", {
    "load": function(e) {
        alert("photo loaded");
    }
});

But:

$("#browser").delegate( ".photo", "load",
    function(e) {
        alert("photo loaded");
});

And you cannot use live and delegate with those events, because they don't bubble.

like image 90
Aidiakapi Avatar answered Oct 28 '22 12:10

Aidiakapi


These events do not bubble, so they cannot be used with live or delegate.

like image 42
SLaks Avatar answered Oct 28 '22 12:10

SLaks