jQuery load() Method

jQuery load() method is used to attaches event handler to the load event. The jQuery load event occurs when a specified element has been loaded. And when the load event occurs, specified function will execute.

The load() method was deprecated in jQuery 1.8. and removed om jQuery 3.0.

Syntax

This syntax represent to the load() method

$(selector).load(function);
Parameter Type Description
function Function Optional. Specifies the function to execute when the event is occurs

Example

This example represent the load event, it will attaches event handler to the load event on the selected elements.

<!DOCTYPE html>
<html>
<head>
  <title>jQuery load() method</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
  <script>
    $(document).ready(function(){
      $("img").load(function(){
        $("div").text("This text comes, when load event triggered on selected element.");
      });
    });
  </script>
</head>
<body>
    <img src="../../images/img_nat.png" width="207" height="137" />
    <div>Image is loading...</div>
</body> 
</html>

Run it...   »