Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery onload function

Tags:

jquery

I m using the following script to call a onload function but it does not works in IE

("#body").attr({onload : "calFact();"});

like image 218
Shaun Avatar asked Sep 02 '10 04:09

Shaun


People also ask

What is onload function in jQuery?

on( "load", handler ) . The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.

Is there an onload function in JavaScript?

In JavaScript, this event can apply to launch a particular function when the page is fully displayed. It can also be used to verify the type and version of the visitor's browser. We can check what cookies a page uses by using the onload attribute.

What is the use of load () function?

The Load function initializes a database and loads it from an input data file. It can be used for initial loading of a database, as part of a database reorganization, or for reloading a database after changing the DBD definition.

What does $( document .ready function () mean?

$( document ).ready()A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.


1 Answers

If you are using jQuery you could use the ready() function like so:

$(function() {
  callFact();
});

or even more simply, just pass the method to jQuery:

$(callFact);

That will fire as soon as the DOM is available to manipulate, sometimes earlier than onload.

like image 131
gnarf Avatar answered Oct 25 '22 17:10

gnarf