In this blog post, we will understand how we can add a click event to a button using a few different techniques.
Why Do You Need A Click Event?
Buttons in HTML perform an action.
This can be submitting a form, starting or stopping an operation, triggering a process, or just visually changing the website. All of the above happens when the user clicks a button.
Adding A OnClick Event To A Button
Using this onClick event we will perform different actions.
We can also write the above example as below:
Then we call the function from the onclick event on the HTML button.
Both the examples above perform the same exact operation.
The result is an alert box like this: