Question

I'm an absolute noob when it comes to this so please take it easy on me.

I'm trying to add a javascript file to my django static js folder. In this .js file I'd like to use JQuery functions.

Is there a javascript equivalent to python's from foo import bar ? How does my javascript file know that $ is referring to a JQuery function? My assumption is that it's all done by the order in which I load the assets and by some magic the functions just become available but that seems a bit ridiculous.

Was it helpful?

Solution

Just make sure you load the jQuery script file before you load your own static .js file.

Here is an example of what you might put in your html head tag if you are hosting it yourself (I put in the Django handlebar syntax for your convenience):

<script src="{{ STATIC_URL }}jquery.min.js"></script>
<script src="{{ STATIC_URL }}myfile.js"></script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top