Reputation: 4318
I need some help. Is there a way to use javascript to add scripts src's to the end of the head? I have some dynamic scripts that are now allowing me to put my scripts at the bottom of the head Is there a way to do this with javascript.
For example, I need these to be at the bottom of the head tag:
<script src="/jQuerySlider/jquery-1.6.4.js" type="text/javascript"></script>
<script src="/jQuerySlider/jquery.easing.1.3.js" type="text/javascript"</script>
Upvotes: 1
Views: 407
Reputation: 154818
You can do so by using createElement
for creating a <script>
element, and then using appendChild
to append (i.e. at the bottom) the script element to the <head>
element:
var scriptElement = document.createElement("script"); // a new <script>
scriptElement.setAttribute("src", "/....js"); // set src
scriptElement.setAttribute("type", "text/javascript"); // not mandatory in HTML5
var head = document.getElementsByTagName("head")[0]; // the <head>
head.appendChild(scriptElement); // append, so at bottom
Upvotes: 2