Reputation: 8742
my template references jQuery in the following way:
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
These two lines are placed at the very end of the body tag in my html file. The static part simply references the location of my js file, this is the way its done in Django I believe.
The html, css and js for the function that I want to implement can be found in this link: Js Fiddle Link
Now I know how the different parts work together, but how I do I bring them in my template in a way that works? I tried putting the jQuery code in a script tag on my html file but it did not affect anything.
What is the correct method of implementing this function?
Upvotes: 1
Views: 499
Reputation: 555
You can add another script tag and place your Javascript or Jquery code inside that, like this:
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script type="text/javascript">
$(document).ready(function(){
// your code
});
</script>
Alternatively you can place you code in a file in your static files, and then import it. So if you add your myJavascript.js
file in your 'static/js' folder, you can include it like this after your jquery and bootstrap:
<script src="{% static 'js/myJavascript.js' %}"></script>
Remember to load your static files at the top of the html file with {% load staticfiles %}
Upvotes: 3
Reputation: 599796
There is nothing Django or Bootstrap specific here. If you have jQuery code, you need to include it after jQuery itself has been loaded.
Upvotes: 1