document.createelement('div') doesn't work?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andy Gritsan
    New Member
    • Jul 2011
    • 3

    #1

    document.createelement('div') doesn't work?

    Code:
    <html>
    <head>
    <title>||Working with elements||</title>
    </head>
    
    <script type="text/javascript">
    var my_div = null;
    var newDiv = null;
    
    function addElement()
    {
      // create a new div element
      // and give it some content
      newDiv = document.createElement("div");
      newDiv.innerHTML = "<h1>Hi there and greetings!</h1>";
    
      // add the newly created element and it's content into the DOM
      my_div = document.getElementById("org_div1");
      document.body.insertBefore(newDiv, my_div);
    }
    
    </script>
    
    <body onload="addElement()">
    <div id='org_div1'> The text above has been created dynamically.</div>
    <script>
    var div = document.getElementsByTagName("div");
    document.write("<br>div= "+div.length);
    </script>
    </body>
    </html>
    here div.length=1
    Last edited by Niheel; Jul 29 '11, 03:55 PM.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It works fine. If you're opening it from your local machine, your browser might be blocking the script.

    Comment

    Working...