Reputation: 73
I want to call a jquery function on load of the page. There is also another Javascript getting called onload of the body tag.
Upvotes: 2
Views: 25015
Reputation: 39649
No problem - they won't conflict with each other:
$(window).load(function() {...});
or...
$(document).ready(function() {...});
Use the second one if you don't need to wait for images and other external dependencies. It simply waits for the DOM to be "ready" (i.e., completely constructed).
Upvotes: 8
Reputation: 4221
There is a jQquery handler called .ready() that will do what you want. It executes with the DOM is ready. See also Use Onload or ready? for a discussion about the differences between ready and onload.
Upvotes: 3
Reputation: 630349
You can do it like this:
$(function() {
//do something
});
Or if you already have the function, like this:
function myFunction() {
//do something
}
You can call it like this:
$(myFunction);
Both of the above are equivalent to $(document).ready(function);
, they're just shortcuts.
Upvotes: 12