JavaScript element.removeEventListener() Method
You are Here:
JavaScript element.removeEventListener() Method
The element.removeEventListener()
method removes the specified event handler from the current element that was registered earlier with the element.addEventListener() method.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<div>Move your mousepointer over here.
<p>Click on the button to remove 'addEventListener()' Method.</p>
<button onclick="myFunction()">Click Me</button>
<p id="point"></p>
</div>
<script>
var x = document.getElementById("point");
var elem = document.getElementsByTagName("div")[0];
function pointerFunction(e){
var xCoords = e.clientX;
var yCoords = e.clientY;
var result = "X coords = "+xCoords+" ,Y coords = "+yCoords;
x.innerHTML = result;
}
function myFunction(){
elem.removeEventListener("mousemove", pointerFunction)
}
elem.addEventListener("mousemove", pointerFunction)
</script>
</body>
</html>
Syntax
element.removeEventListener(event, function, useCapture)
Parameter Values
Value | Type | Explanation |
---|---|---|
event | Required | A case-sensitive string representing the type of event for which to remove an event listener. |
function | Required | Specifies the function to remove. |
useCapture | Optional | A Boolean value that specifies the event phase to remove the event handler from. If true, Removes the event handler from the capturing phase. If false, Removes the event handler from the bubbling phase. This is Default behavior. |
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.