views:

67

answers:

1

I have an image $("#main")

how can I use jquery to dosomething(this) when the image has loaded?

+1  A: 

Use the load() event.

$("#main").load(doSomething);

Within your doSomething() method, this will refer to the DOM image element. Note that it isn't passed as an argument. Just use this within your doSomething() method and it will work.

Keep in mind that the load() event will only fire if the element isn't already loaded. If the image is already loaded, then doSomething will never get called.

Dan Herbert
will that pass the "this"?
steven
I just edited my answer to include that piece of information.
Dan Herbert