The problem is that you're loading jQuery as async:
<script async='async' <----------- this is the problem src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js' type='text/javascript' />
The async property tells your browser that it's OK to load this file later after executing all other javascript code on the page. The solution is to remove the async.
But isn't async recommended?
Yes but only for scripts that other scripts on your page don't depend on. For libraries like jQuery where you need to be certain has been loaded you should not use async.
But wouldn't it slow down page load if the browser waits for jQuery?
Yes, the solution to this is to move all your script tag to the bottom of the page, outside <head>, just before the closing of the <body> tag:
<html> <head></head> <body> some stuff... <script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js' type='text/javascript' /> <script type='text/javascript'> ;(function ($, document, window) { var // default settings object. defaults = { label: 'MENU', duplicate: true, duration: 200, easingOpen: 'swing', easingClose: 'swing', closedSymbol: '►', openedSymbol: '▼', prependTo: 'body', parentTag: 'a', closeOnClick: false, allowParentLinks: false, nestedParentLinks: true, showChildren: false, init: function(){}, open: function(){}, close: function(){} },... </script> </body> </html>
But I (or my boss) don't like script outside of head!!
Well, you can still have your script in head but it's a bit involved. Basically you need to listen to the onload event of the jquery script tag. But that means you need to create the tag dynamically instead of hardcoding it in html:
<html> <head> <script> var jq = document.createElement('script'); jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"; jq.async = true; // you can still load as async! jq.onload = function () { (function ($, document, window) { var // default settings object. defaults = { label: 'MENU', duplicate: true, duration: 200, easingOpen: 'swing', easingClose: 'swing', closedSymbol: '►', openedSymbol: '▼', prependTo: 'body', parentTag: 'a', closeOnClick: false, allowParentLinks: false, nestedParentLinks: true, showChildren: false, init: function(){}, open: function(){}, close: function(){} },... }; document.head.appendChild(jq); </script> </head> <body> .... </body> </html>
onload="someFunc()"in the jQuery script tag, and wrapping the code you have infunction someFunc() { ... your code ... }