Nitzan
Nitzan

Reputation: 91

What triggers the firing of the "onLoad" event?

If I want to change a div background image using jQuery, does it trigger the $(window)'s onLoad function?

Upvotes: 1

Views: 793

Answers (2)

Techie
Techie

Reputation: 45124

onLoad executes a JavaScript immediately after a page has been loaded.

The onload event occurs when an object has been loaded. onload is most often used within the element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.).

In JavaScript Syntax:
    object.onload="SomeJavaScriptCode"

onload is Supported by the Following HTML Tags:

<body>, <frame>, <frameset>, <iframe>, <img>, <input type="image">, <link>, <script>, <style>

If you are into jQuery refer the code below. write the code in the $(document).ready() section. It's a function to execute when the DOM is fully loaded.

$(document).ready(function() {
  // Handler for .ready() called.
  //code to change the background
});

Which is equivalent to calling:

$(function() {
 // Handler for .ready() called.
 //code to change the background
});

read more

Hope this will solve your problem. If you have any questions please don't hesitate to ask. Thanks.

Upvotes: 0

Guffa
Guffa

Reputation: 700592

No, the load event for window (which is the same as the one for document) is triggered when the document has been loaded and then loaded all initial content.

Making a style change that causes something to load doesn't retrigger the event.

Upvotes: 1

Related Questions