Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top