Use the onclick attribute to execute a script when an element is clicked in HTML.
<!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>
The above is the detailed content of Execute script when HTML element is clicked?. For more information, please follow other related articles on the PHP Chinese website!