views:

83

answers:

2

i'm trying to write a jquery plugin that when i click on a image to pop an alert message. Those images are loaded via load() method. Is there possible to load the plugin on document ready and the plugin to have acces to the loaded content? i don't want to use a callback function, i just want to include the plugin in the html page and then the plugin do it's thing.

A: 

Try using live events to catch the click event for all img elements, whenever they were added.

SLaks
A: 

If I understand you correctly, you probably want to use the jQuery.live method to bind an onClick handler to all present AND future images that conform to a query. For example, you can say

$("img.alerting").live("click", function(){
    alert("This image's src is " + this.src);
});

And then every image with the "alerting" class will always have a click handler, even images that didn't exist when you ran the above code.

Eli Courtwright
yeah, that's what i'm trying to do but...on page load there are no images so my code gets interrupted. i tried to figure out something with live but with no success that's why i'm asking you
kmunky
there's no other way? live works against a selector, but on my page load i have no elements that match my query
kmunky
ouh my bad, i mis-typed something that's why it wasn't working. but now it's ok. thanks guys for your answers.
kmunky