You should always start your jQuery using the ready() function. The handler passed to .ready() function is guaranteed to be executed after the DOM is ready.
There are a few ways to start your jQuery function, but all are equivalent:
$(document).ready(function() { // Do some magic }); $().ready(function() { // A bit quicker to write }); $(function() { // Nice shorthand that I prefer to use });
There is a fourth...
ReplyDeletejQuery(function($) {
// Nice shorthand that everyone should use!
});
...so you know the $ symbol refers to the jQuery library (in case you use more than one).
Good point Mr Gunn!
ReplyDelete