
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Execute a Script When an Element is Clicked in HTML
Use the onclick attribute to execute a script when the element is clicked in HTML.
Example
You can try to run the following code to implement onclick attribute −
<!DOCTYPE html> <html> <body> <button onclick = "display()">Click</button> <p id = "test"></p> <script> function display() { document.getElementById("test").innerHTML = "You clicked the button!"; } </script> </body> </html>
Advertisements