What is Onclick Event in JavaScript



The onClick event is the most frequently used event type, which occurs when a user clicks the left button of the mouse.

Example

You can put your validation, warning etc., against this event type.

Live Demo

<html>
   <head>
      <script>
         <!--
            function sayHello() {
               alert("Hello World")
            }
         //-->
      </script>
   </head>
   <body>
      <p>Click the following button and see result</p>
      <form>
         <input type="button" onclick="sayHello()" value="Say Hello" />
      </form>
   </body>
</html>
Updated on: 2020-01-08T10:19:53+05:30

490 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements