2

Inline in the HTML (without using a separate javascript file or code block) how to change display of element on page load? I want it to go from display:none back to default.

I've tried this:

<div style="display:none" onload="function(){this.style.display = 'block'}">
   hello
</div>

And this:

<div style="display:none" onload="this.style.display = ''">
    hello
</div>

But doesn't work, thanks.

Andrew
  • 18,680
  • 13
  • 103
  • 118

1 Answers1

2

As I wrote in comment under question, there is no onload event for div.

You can use this code, it changes the divs display value when document is loaded.

document.onload = document.getElementById('div').style.display = 'block';
<div style="display:none" id="div">
   hello
</div>
pavel
  • 26,538
  • 10
  • 45
  • 61