Use the onload attribute to execute a script when the element is finished loading.
Example
You can try to run the following code to implement onload attribute −
<!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>