EN
JavaScript / HTML - onload event doesn't work with div elements
1
answers
0
points
How can I add onload to the div
element? It doesn't seem to work.
Example:
<!doctype html>
<html>
<body>
<div id="div-id" onload="console.log('Hello World!');">div text</div>
</body>
</html>
1 answer
0
points
The onload
event can't be used with div elements. It can only be used on the document, body, frames, images, and scripts.
However, you can add <script>
tag performing some action right after the <div>
to be executed immediately, like this:
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<body>
<div id="div-id">div text</div>
<script>console.log('Hello World!');</script>
</body>
</html>
See also
0 comments
Add comment