Home > Article > Web Front-end > How to remove onclick event in javascript
Javascript method to remove onclick event: 1. Use the "document.getElementById("id value")" statement to obtain the element object based on the id value; 2. Use the "element object.onclick=null;" statement to Just remove the onclick event.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
How to remove the onclick event in javascript
You can use the "document.getElementById("id value")" statement to obtain the element object based on the id value ;Then use the "element object.onclick=null;" statement to remove the onclick event.
The example of removing element onclick event is as follows:
<html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> <script> function myFunction(){ document.getElementById("mybutton").onclick=null; document.getElementById("demo").innerHTML="Hello World"; } </script> </head> <body> <p>单击按钮触发函数。</p> <button onclick="myFunction()" id="myburtton">点我</button> <p id="demo"></p> </body> </html>
Output result:
(Learning video sharing: css video tutorial )
The above is the detailed content of How to remove onclick event in javascript. For more information, please follow other related articles on the PHP Chinese website!