Onload event does not work with Internet Explorer

I wrote very simple code in Internet Explorer 8, and I don’t understand why nothing happens when I open a page with IE (why the text “test” does not appear on the page).

I tried Firefox and Chrome and it works great.

my code is:

<html>
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso 8859-1" />

   <script type="text/javascript">

   function display() {
      output.innerHTML+='test';
   }

   </script>

   </head>

   <body onload="display()">

      <div id="output">
      </div>
   </body>
</html>

Edit: let IE change the settings, don’t do it manually or it gets weird :-))

+3
source share
2 answers
document.getElementById('output').innerHTML += 'test';
+3
source

Try:

   function display() {
      document.getElementById('output').innerHTML+='test';
   }
+3
source

All Articles