Ensuring load code fires in jQuery event if attaching event after load occurs?

You can do this using one() and complete like this: $('#image'). One('load', function () { if ($(this).width() Complete) $(this). Trigger('load'); }) one() ensures the handler only executes once.

The loop at the ends checks if the complete of the image is true, for example when it loads from cache or has already loaded for some other reason, and if it's true, triggers the load event...the one() prevents this from causing the load code to fire twice as a result of this.

You can do this using .one() and . Complete like this: $('#image'). One('load', function () { if ($(this).width() Each(function() { if(this.

Complete) $(this). Trigger('load'); }); .one() ensures the handler only executes once. The loop at the ends checks if the .

Complete of the image is true, for example when it loads from cache or has already loaded for some other reason, and if it's true, triggers the load event...the .one() prevents this from causing the load code to fire twice as a result of this.

The this. Complete is just what I was looking for! Thanks!

– Boushley May 5 '10 at 17:48 Brilliant. Solved a problem I've been working on for a few hours rawr. Thanks!

– Stefan Mai Oct 4 '10 at 7:43.

I'm trying to figure out how I can best attach a load event to an element, but be sure that it gets run. The issue comes when I bind to the load event of an img, but that binding happens too late and the image has already loaded. Is there some way in jQuery to check if the image is already loaded?

Its obviously an intermittent issue, because sometimes the code is run before the image loads and sometimes its not. The code looks something like that. I've added the hasRun variable and a check against the height and width of the variable to ensure its loaded, and then added the trigger.

Is there a better way to do this? Is there some flag I can set with jQuery to tell it to run the function if the image is already loaded?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions