steven
steven

Reputation: 13547

on image load dosomething(this) in JQuery

I have an image $("#main")

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

Upvotes: 1

Views: 559

Answers (1)

Dan Herbert
Dan Herbert

Reputation: 103457

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.

Upvotes: 1

Related Questions