JavaScriptr removeEventListener

JavaScriptr removeEventListener


JavaScriptr removeEventListener
In this tutorial, you will learn about JavaScript removeEventListener() method:
  • The EventTarget.removeEventListener() method removes from the EventTarget an event listener previously registered with EventTarget.removeEventListener().
  • The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching event listeners for removal.
The Syntax of JavaScriptr removeEventListener
element.removeEventListener(event, listener, useCapture)
Example
Output
After clicking the button
Javascript Timer
 
Timer events
method 
description 
setTimeout(function, delayMS); 
arranges to call given function after given delay in ms 
setInterval(function, delayMS); 
arranges to call function repeatedly every delayMS ms 
setTimeout(timerID);
setInterval(timerID); 
stops the given timer so it will not call its function 
Note : this ID can be passed to clearTimeout/Interval later to stop the timer
Example
 
Passing parameters to timers
function delayedMultiply() {
// 6 and 7 are passed to multiply when timer goes off
setTimeout(multiply, 2000, 6, 7);
}
function multiply(a, b) {
alert(a * b);
}
  • any parameters after the delay are eventually passed to the timer function
  • why not just write this? 
setTimeout(multiply(6 * 7), 2000);
Common timer errors
setTimeout(booyah(), 2000);
setTimeout(booyah, 2000);
setTimeout(multiply(num1 * num2), 2000);
setTimeout(multiply, 2000, num1, num2);
  • what does it actually do if you have the () ?
  • it calls the function immediately, rather than waiting the 2000ms!