I am testing this fiddle written by @Ilan Biala
It adds a submenu in a menu using jquery 1.9.0, onDomReady and Normalized css as you can see on the jsfiddle.
For instance the html is:
<nav>
<ul>
<li><a href="#" >Sec1</a></li>
<li><a href="#" >Sec2</a></li>
<li><a href="#" class="current">Sec3</a></li>
<li><a href="contacto.html" >Sec4</a></li>
<ul class="menu">
<li><a href="#" class="documents" data-icon="">Documents</a></li>
<br>
<li><a href="#" class="messages" data-icon="">Messages</a></li>
<br>
<li><a href="#" class="signout" data-icon="">Sign Out</a></li>
</ul>
</ul>
</nav>
the result is:

But there is an issue, I am adding the code to a server I have access, and Added the lines:
<link rel="stylesheet" type="text/css" href="css/menu.css" />
<script type="text/javascript" src="js/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
to emulate those in jsfiddle. The html is:
<!doctype html>
<head>
<title>Example</title>
<link rel="stylesheet" type="text/css" href="css/menu.css" />
<script type="text/javascript" src="js/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
</head>
<body>
<nav>
<ul>
<li><a href="#" >Sec1</a></li>
<li><a href="#" >Sec2</a></li>
<li><a href="#" class="current">Sec3</a></li>
<li><a href="contacto.html" >Sec4</a></li>
<ul class="menu">
<li><a href="#" class="documents" data-icon="">Documents</a></li>
<br>
<li><a href="#" class="messages" data-icon="">Messages</a></li>
<br>
<li><a href="#" class="signout" data-icon="">Sign Out</a></li>
</ul>
</ul>
</nav>
</body>
</html>
So, as you can see the submenu is not working, what could be causing the glitch?
I am suspecting different issues:
-
Maybe the onDomReady property that wraps the code so it will run in onDomReady window event, if so How do I indicate that on code :
$(document).ready(function() {
//ADD ALL THE JS CODE IN menu.js
}); -
The Normalized css, but that is suposed to make a reset….
-
Theres is an issue in the jquery 1.9.0, maybe the order the using js are placed…
What do you think?
See the same fiddle here modified to work with what you want: JS Fiddle Link
Its the exact same fiddle that you posted, just onDomReady set to “no wrap (head)” and JavaScript code wrapped in
readyfunction. This makes it work with the HTML you have posted.So, as an answer, when you have jQuery loaded in
headtag of yourhtmldocument, you need to use.ready()API of jQuery and wrap all your code for any DOM manipulation in thereadyfunction