Load Events
The load event will fire on any resource (window, document, image, stylesheet, script, video/audio file) that has finished loading -- this also includes any dependent resources.
<!-- HTML -->
<img src="http://example.com/example.jpg width="100" height="100" alt="Example Image" />
// JavaScript
var image = document.querySelector('img');
image.addEventListener('load', function(event) {
image.classList.add('has-loaded');
});
<!-- HTML Output Result -->
<img src="http://example.com/example.jpg" class="has-loaded" width="100" height="100" alt="Example Image" />Written by Brian
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Events
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#