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
  • 16,273
  • 10
  • 93
  • 104

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
  • 25,361
  • 10
  • 41
  • 58