I am currently developing a HTML5 page, so I want to use jQuery for some effects. Here’s my code that doesn’t seem to work:
The html code:
<nav id="mainNavigation">
<!--....-->
</nav>
and now jQuery:
$('#mainNavigation').click(function(){
alert("test");
});
For some reason, nothing is happening. When I try something like:
$(document).ready(function(){
alert("test");
})
everything works fine.
Thank you for any help.
It sounds like you aren’t wrapping your code in a document ready. This is basically telling the code to run with the DOM is ready.
Are you doing this:
As per motoxer4533’s comment you can also do this via jQuery’s shorthand Document ready: