Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Apend head element

    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 ?

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    document.getElementsByTagName('head')[0].appendChild(...)
    Last edited by Harry Armadillo; 03-29-2005 at 10:10 AM. Reason: typing faster than thinking

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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');
    Last edited by Kor; 03-30-2005 at 08:45 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •