Click Click

Home >Web Front-end >HTML Tutorial >Execute script when HTML element is clicked?

Execute script when HTML element is clicked?

王林
王林forward
2023-08-30 21:29:021433browse

Execute script when HTML element is clicked?

Use the onclick attribute to execute a script when an element is clicked in HTML.

Example

You can try running the following code to implement the 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>

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete