Home > Web Front-end > JS Tutorial > body text

How to remove onclick event in javascript

WBOY
Release: 2021-12-14 15:58:19
Original
6641 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!