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 D
write the code that you want to be executed inside this. When your document is ready, this will be executed.
$(document).ready(function() { });