1

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> 
1
  • I am not sure your question makes sense. The browser normally loads all the scripts that is required by the page. So dynamically creating these scripts, I am not sure if it will give you desired functionality. I am assuming your dynamic scripts you mentioned earlier are server scripts... Commented Nov 15, 2011 at 16:34

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.