ใช้ onload แอตทริบิวต์เพื่อรันสคริปต์เมื่อองค์ประกอบโหลดเสร็จ
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อใช้แอตทริบิวต์ onload −
<!DOCTYPE html>
<html>
<head>
<script>
function display() {
alert("Welcome!");
}
</script>
</head>
<body onload = "display()">
<h3>Welcome to the website.</h3>
<p>We offer learning content.</p>
</body>
</html>