3

I have a jquery function that works great hard coded onto the html page right above the head tag

<script type="text/javascript" src="js/jquery.js"></script>    
<script>
$(document).ready(function() {
$('#side-menu').sidr();
});
</script>
</head>

however when i move this to the external .js file that is also right above the head tag, it doesn't work. I'm formatting it on the external.js file like this:

$(document).ready(function() {
$('#side-menu').sidr();
});

and including my external.js file on the html like this:

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/external.js"></script>
</head>

is there some syntax i'm missing?

5
  • 1
    you need to include your external js file. Commented Feb 14, 2015 at 23:54
  • and include it after you include jQuery Commented Feb 14, 2015 at 23:57
  • yup, doing that. just edited my question to reflect that. any other reasons it might not be working? thanks guys! Commented Feb 15, 2015 at 0:05
  • Have you included the sidr plugin library? Commented Feb 15, 2015 at 0:29
  • yup, no typos, but it's definitely not loading. when hard coded it adds a class to the #side-menu div, but when extrnal and i check the source that class hasn't been added. i see this answer here: stackoverflow.com/questions/17600264/… but i'm not sure what i'm supposed to wrap the function in. his example is a bit different than mine and i'm not advanced enough to know how to modify it. thanks again for any help. Commented Feb 15, 2015 at 0:34

2 Answers 2

3

Without seeing your page I don't know how you are laying it all out, but since it works inline but not externally you could make sure you put:

<script type="text/javascript" src="js/external.js"></script>

...in the same place as you had:

$(document).ready(function() {
$('#side-menu').sidr();
});
Sign up to request clarification or add additional context in comments.

1 Comment

That was it! i had the order mixed up with other scripts, that's why it wasn't running. can't believe i didn't notice that. thanks.
0
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
    <script src="js/app.js"></script>
</head>

The jquery src should be always above those external .js files that use jquery.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.