removeEventListener() 예제
<style> #hz { background-color: coral; border: 1px solid; padding: 50px; color: white; } </style> <div id="hz">홈짱닷컴 Homzzang.com <button onclick="removeEvent()" id="btn">클릭</button> </div> <p id="demo"></p> <script> document.getElementById("hz").addEventListener("mousemove", homzzang); function homzzang() { document.getElementById("demo").innerHTML = Math.random(); } function removeEvent() { document.getElementById("hz").removeEventListener("mousemove", homzzang); } </script> 결과보기
<style>
#hz {
background-color: coral;
border: 1px solid;
padding: 50px;
color: white;
}
</style>
<div id="hz">홈짱닷컴 Homzzang.com
<button onclick="removeEvent()" id="btn">클릭</button>
</div>
<p id="demo"></p>
<script>
document.getElementById("hz").addEventListener("mousemove", homzzang);
function homzzang() {
document.getElementById("demo").innerHTML = Math.random();
function removeEvent() {
document.getElementById("hz").removeEventListener("mousemove", homzzang);
</script>
결과보기