<html> <body> <h1>The onclick Event</h1> <p>The onclick event triggers a function when an element is clicked on.</p> <p>Click to trigger a function that will output "Thankyou Workingcode.in":</p> <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = "Thankyou Workingcode.in"; } </script> </body> </html>
Output:
onclick Function JavaScript or Call a function when a button is clicked
Working Code Asked question September 21, 2023