Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14174 > unrolled thread
| Started by | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| First post | 2012-05-27 20:04 +1000 |
| Last post | 2012-05-27 12:21 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.javascript
Removing event handler Andrew Poulos <ap_prog@hotmail.com> - 2012-05-27 20:04 +1000
Re: Removing event handler Martin Honnen <mahotrash@yahoo.de> - 2012-05-27 12:21 +0200
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2012-05-27 20:04 +1000 |
| Subject | Removing event handler |
| Message-ID | <RYCdnSEKaLK3YVzSnZ2dnUVZ_v2dnZ2d@westnet.com.au> |
If I have an onclick event handler I can "remove" it anywhere with
elem.onclick = null;
But if the handler is added using addEventListener which is in this sort
of code
var a = function(o) {
var transformer = function() {
// do stuff
}
o.elem.addEventListene("click", transformer, false);
}(obj);
How can I remove the event handler outside of 'a'?
Andrew Poulos
[toc] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2012-05-27 12:21 +0200 |
| Message-ID | <4fc20039$0$6553$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #14174 |
Andrew Poulos wrote:
> If I have an onclick event handler I can "remove" it anywhere with
>
> elem.onclick = null;
>
> But if the handler is added using addEventListener which is in this sort
> of code
>
> var a = function(o) {
> var transformer = function() {
> // do stuff
> }
>
> o.elem.addEventListene("click", transformer, false);
>
> }(obj);
>
> How can I remove the event handler outside of 'a'?
There is a removeEventListener function
(https://developer.mozilla.org/en/DOM/element.removeEventListener) but
you would need to store the event listener (function object) you passed
in to addEventListener to be able to remove it later.
--
Martin Honnen --- MVP Data Platform Development
http://msmvps.com/blogs/martin_honnen/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web