getElementsByTagName("head")[0].appendChild(js);

Discussion in 'JavaScript' started by KennyTE, Jul 1, 2007.

  1. #1
    can someone explain what below code means?

    document.getElementsByTagName("head")[0].appendChild(js);
     
    KennyTE, Jul 1, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    That's a way to include an element into the DOM (Document Object Model) dinamically. In this case is inserted at the end of <head> section, and probably "js" is a string with something like this:
    
    <script src="script_1.js" language="JavaScript" type="text/javascript"></script>
    
    Code (markup):
    That way you can load different scripts easily using "script_1.js", "script_2.js", etc.
     
    ajsa52, Jul 1, 2007 IP