Answer the question
In order to leave comments, you need to log in
Anonymous functions and removeEventListener?
Good afternoon!
There is this code :
function text(a) {
alert(a);
}
el.addEventListener('click', function() {
text('it\'s finnaly working!');
});
el.removeEventListener('click', function() {
text('it\'s finnaly working!');
});
Answer the question
In order to leave comments, you need to log in
It's simple: don't use anonymous functions.
var f1 = function() {
text('it\'s finnaly working!');
};
el.addEventListener('click', f1);
// ...
el.removeEventListener('click', f1);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question