1.

Increase the size of the text content in JavaScript

Answer»

The onclick event gets triggered in JavaScript when a user clicks on any of the HTML ELEMENT such as on click of a button.

Let us see an example of onclick event in JavaScript WHEREIN the event gets triggered when left button of the mouse is clicked:

&LT;html>    <head>       <script>          <!--             function SHOW() {                alert("This is a message!")             }          //-->       </script>    </head>    <body>       <p>Click the below button:</p>       <form>          <input type="button" onclick="show()" value="Display" />       </form>    </body> </html>

The output displays a button:

Event gets triggered when you click on the button to generate the following alert: 

Let us see ANOTHER example wherein we are displaying the current date and time on click of a button: 

<!DOCTYPE html> <html> <body> <button onclick="document.getElementById('myid').innerHTML=Date()">Time</button> <h2 id="myid"></h2> </body> </html>

The following output generates on the click of a button that we created in the example above: 



Discussion

No Comment Found