Event Handling

HTML

<button onclick="sayHello()">Click Me</button>

JavaScript

function sayHello() {
  alert("Hello! You clicked the button.");
}

Explanation:

  • onclick calls the sayHello() function.
  • alert() shows a popup message.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *