This is the first thing to learn about jQuery: If you want an event to work on your page, you should call it inside the
$(document).ready() function. Everything inside it will load as soon as the DOM is loaded and before the page contents are loaded.
<a href> tag.
$(document).ready(), you can get your events to load or fire or whatever you want them to do before the window loads. Everything that you stick inside its brackets is ready to go at the earliest possible moment — as soon as the DOM is registered by the browser, which allows for some nice hiding and showing effects and other stuff immediately when the user first sees the page elements.
UpdateI thought it might help the absolute beginners to see an example of the
<head>where you would include your scripts. Note that CSS stylesheets come before the jQuery file, and the jQuery file comes before your custom script:
It is in "yourcustomscript.js" that you would place your script inside the