I have a problem
open: function($type) {
//Some code
document.getElementById($type).addEventListener("click", l.close($type), false);
},
close: function($type) {
//There is some code too
document.getElementById($type).removeEventListener("click", l.close($type), false);
//^ Recursion & Uncaught RangeError: Maximum call stack size exceeded
}
What I'm doing wrong? Without this click event listener everything is working well. And what is the third parameter doing (true|false)? Thank you.
I have a problem
open: function($type) {
//Some code
document.getElementById($type).addEventListener("click", l.close($type), false);
},
close: function($type) {
//There is some code too
document.getElementById($type).removeEventListener("click", l.close($type), false);
//^ Recursion & Uncaught RangeError: Maximum call stack size exceeded
}
What I'm doing wrong? Without this click event listener everything is working well. And what is the third parameter doing (true|false)? Thank you.
Share Improve this question asked Feb 29, 2012 at 10:57 anony_rootanony_root 1,5274 gold badges16 silver badges25 bronze badges 1- developer.mozilla/en/DOM/element.removeEventListener the third parameter flags whether or not you want the event listener to use event capturing (as oppose to bubbling) on adding, and on removal whether or not the event was added as such. – davin Commented Feb 29, 2012 at 11:04
2 Answers
Reset to default 9You are calling the close
function in the addEventListener
and removeEventListener
when you are trying to pass is as an argument (causing an infinite loop). Instead you should simply pass the reference to the function as follows:
document.getElementById($type).addEventListener("click", l.close, false);
And:
document.getElementById($type).removeEventListener("click", l.close, false);
Or you might have two Javascript functions with the same name.