Home  >  Article  >  Web Front-end  >  How to remove onclick event in javascript

How to remove onclick event in javascript

WBOY
WBOYOriginal
2021-12-14 15:58:196642browse

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.

How to remove onclick event in javascript

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:

How to remove onclick event in javascript

(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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn