What is Window Load Method in jQuery



The code which gets included inside $( window ).on( "load", function() { ... }) runs only once the entire page is ready (not only DOM).

Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.

Example

You can try to run the following code to learn how to use $(window).load() method in jQuery −

Live Demo

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
   $("img").load(function(){
     alert("Image successfully loaded.");
   });
});
</script>
</head>
<body>

<img src="/https/www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg" alt="Tutor" width="280" height="236">

<p><strong>Note:</strong> The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.</p>

</body>
</html>
Updated on: 2020-02-14T04:57:45+05:30

460 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements