I wanted to know how to use jQuery to create a function that will run whenever the image is loaded. I want this feature to be called EVERY TIME, not just once. So if, for example, I have "image1.jpg" and it was loaded at the start of the page, the function will be called. Then, if I changed the image and it was loaded again after I changed it using Javascript, I want this function to โloadโ to run again. I tried the Jquery Load () function, but it runs only once, not the second time after replacing the image with another.
I also want this to happen, even if the image was cached too. This means that every time I change the src attribute 'src' for an image, I want some function to be activated - again, even if the image has already been cached.
Example:
$("#myimageselector").attr("src", "http://domain.com/the_new_image.jpg");
I want that when this happens, even if the image is already cached, the function will fire. I think you can find out if there were cached images like. I just need to have a .load () function that will execute once (of course), and if it has not been executed, it means the image has been cached. At least for my specific use.
Thought: perhaps we need to bind an event that will check the change in the DOM for a specific change to the element. Therefore, it is possible that if the image was finished, then a specific DOM element will be changed, so we can check the values โโbefore and after.
Thanks.
source share