I have an image $("#main")
how can I use jquery to dosomething(this) when the image has loaded?
I have an image $("#main")
how can I use jquery to dosomething(this) when the image has loaded?
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.