How to call a JavaScript function from an onClick event?

The onClick event is the most frequently used event type, which occurs when a user clicks the left button of the mouse. You can put your validation, warning etc., against this event type.

Example

You can try to run the following code to call a JavaScript function from an onClick event

   
      
   
   
      

Click the following button and see result

     
               
   
Updated on: 2026-03-11T23:14:17+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements