x
1
2
<html>
3
<head>
4
<title>CloseTag | JavaScript removeEventListener</title>
5
<style>
6
#btn
7
{
8
Background-color:#007bff;
9
color:white;
10
padding:10px;
11
border:none;
12
}
13
</style>
14
</head>
15
<body>
16
<h1 id="h1">JavaScript removeEventListener</h1>
17
<p id="paragraph">random number <span id="number"> </span><p>
18
<button id="btn">Remove</button>
19
<script>
20
let number = document.getElementById("number");
21
let btn = document.getElementById("btn");
22
window.addEventListener("mousemove", randomiz);
23
24
function randomiz(){
25
document.getElementById("number").innerHTML = Math.random();
26
}
27
28
btn.addEventListener("click", function(){
29
window.removeEventListener("mousemove",randomiz);
30
});
31
</script>
32
</body>
33
</html>