-
$(document).ready(function(){ ... });
or short$(function(){...});
This Function is called when the
DOM is ready
which means, you can start to query elements for instance..ready()
will use different ways on different browsers to make sure that the DOM really IS ready. -
(function(){ ... })();
That is nothing else than a function that invokes itself as soon as possible when the browser is interpreting your
ecma-/javascript
. Therefor, its very unlikely that you can successfully act onDOM elements
here.