Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Attaching Event Handlers in External File</title> </head> <body> <button type="button" id="myBtn">Click Me</button> <script> function sayHello(){ alert('Hello World!'); } document.getElementById("myBtn").onclick = sayHello; </script> </body> </html>