0

I don't want to add eventListener DOMContentloaded for a moment I just want to is there a way to make a script tag executed after this following div tag

<html>
 <head>


  </head>

   <body>
        <div id="name">12 </div>
        <script>
                  var name =  document.getElementById("name");
                  name.innerHTML = "13"; 
        </script
   </body>    

Also want to know why the script tag is executed before the DOM gets loaded

palak sharma
  • 231
  • 1
  • 12
  • Are you saying that the `div` isn't available when your script runs? What you're currently doing should work. –  Aug 17 '16 at 17:29
  • @Marc B I want to know why the script tag is executed first? The marked question didn't answer my question. – palak sharma Aug 17 '16 at 17:30
  • @squint yes ...Because it is always recommended to put the script tag just before the closing of body tag... So why this is not working – palak sharma Aug 17 '16 at 17:33
  • 1
    Try changing the variable name from `name` to something else, like `x`. There's a default global variable called `name` that gets in the way of your assignment because it converts it to a string. –  Aug 17 '16 at 17:34
  • 1
    thnks it is working now! – palak sharma Aug 17 '16 at 17:37
  • 2
    Glad to hear that. In general, it's not a bad idea to wrap your code in a function so that your variables aren't global. –  Aug 17 '16 at 17:38

0 Answers0