I've code a piece of code that goes like this:
$('img').load(function(){
$(this).doStuff(); // here could be one, two, or more images
doSomethingElse(); // I want this part to run only ONCE
});
function doSomethingElse(){
// code here unfortunately runs one, two, or more times (depending on how many imgs there are)
}
I'm not sure how to apply jQuery .one()
in this situation. I've tried searching online for a way to run something only once, but all I ever seem to find are recommendations to try using jQuery .one()
.
There must be some way to run doSomethingElse
only once, even if multiple images are loaded. I suppose I could use a setTimeout
and wait for all the images to have loaded, but I would be guessing how long this takes so that solution seems a bit weak.