Marius van Witzenburg We fight for our survival, we fight!

15Jun/110

jQuery its ‘document ready’ can be written on different ways.

I have seen a lot of scripts already still using a old way of checking if the DOM is ready for action like this:

1
2
3
4
5
window.onDomReady = myFunction;
 
function myFunction() {
    alert('hello');
}

or (which is not smart cause onload waits for even the images to be loaded):

1
2
3
4
5
window.onload = myFunction;
 
function myFunction() {
    alert('hello');
}

jQuery has a nicer way to implement this with the following piece of code:

1
2
3
$(document).ready(function() {
// your code here
});

However you can write this even a bit shorter than most people already do by using the above code, like this:

1
2
3
$(function() {
// your code here
});

I hope you find this useful, make something nice with jQuery! ;-)

Posted by mariusvw

Reacties (0) Trackbacks (0)

Nog geen reacties


Leave a comment

(required)

Nog geen trackbacks.