What is the purpose of the `onclick` attribute in HTML?

The onclick attribute in HTML is used to specify a JavaScript function or code that should be executed when an element, typically a button, is clicked. It allows you to create interactive web pages by responding to user actions.

Here’s an example:

<button onclick="alert('Hello, World!')">Click Here</button>

In this example, when the button is clicked, an alert box will display the message "Hello, World!".

0 Comments

no data
Be the first to share your comment!