...

View Full Version : Apend head element



hqtrung
03-29-2005, 09:27 AM
How can I append a script element to head element of a document.
I need to add a script tag for javascript file from the body.
ex :
<head>
<script src="myscript1.js />
</head>
<body>
<script language="Javascript">
myscript2 = document.createElement("script");
myscript2.scr = "myscript2.js";
document.head.appendChild(myscript2);
</script>

</body>

This is my idea, can some one help me ?

Harry Armadillo
03-29-2005, 09:48 AM
document.getElementsByTagName('head')[0].appendChild(...)

Kor
03-30-2005, 08:43 AM
1 ...and
myscript2.src = "myscript2.js";
or better
myscript2.setAttribute('src','myscript2.js');

2 ...and, don't forget about the type of the script element

myscript2.setAttribute('type','text/JavaScript');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum