0

onload event in divs is not working

I tried to use onload event in a div, but it's not working Here onload is working https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onload_html I don't want to use onload in body/html / or to use addEventListenr https://code.sololearn.com/WszlNRY8n9Vm/?ref=app

26th Oct 2020, 6:20 AM
Prasant
Prasant - avatar
4 ответов
+ 3
You can't access that DOM element until it's loaded, so you have to add onload in window before you add event on div. Or, put your script after your HTML element(before </body>)
26th Oct 2020, 6:31 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 3
No you can't use onload event on any element except body.
26th Oct 2020, 6:38 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
RDC Can't I add onload directly in a div in HTML part ?
26th Oct 2020, 6:36 AM
Prasant
Prasant - avatar
+ 1
RDC Ok, I got it. Thank you so much
26th Oct 2020, 6:45 AM
Prasant
Prasant - avatar