0

I have the following code

<html>
<head>
    <script>
        document.getElementById("txt").innerHTML = "Hello";
    </script>

</head>
<body>

<div id="txt"></div>

</body>
</html>

and of course the text "Hello" isn't displayed because it's before the div. However because i use egl i can put js code only on head.

Is there any way to fix this?

xarlap
  • 157
  • 1
  • 2
  • 14

1 Answers1

0

You need to wait for your page to be ready before your code can execute on markup in the page. For example, use window.onload handler as in the example below. There are nicer ways to do this such as jQuery methods, but this will serve as an example of what you need.

<html>
<head>
    <script>
        window.onload = function ()
         {
              document.getElementById("txt").innerHTML = "Hello";
         }
    </script>

</head>
<body>

<div id="txt"></div>

</body>
</html>
MatthewG
  • 6,224
  • 2
  • 22
  • 27