Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34114
| From | Richard Maher <maher_rjSPAMLESS@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: removeeventlistener |
| Date | 2017-10-16 13:06 +0800 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <os1eo9$1tb0$1@gioia.aioe.org> (permalink) |
| References | <e4ednXbpPvgtunnEnZ2dnUU7-bXNnZ2d@westnet.com.au> |
On 16-Oct-17 11:29 AM, Andrew Poulos wrote:
> I have code that looks like this
>
> function elementOver() {
> return function() {
> this.style...
> };
> }
>
> function setOver(elem) {
> for (var i = 0; elem.length; i++) {
> elem[i].addEventListener("mouseover", elementOver() );
> }
> }
>
> function disableOver(elem) {
> for (var i = 0; i < elem.length; i++) {
> elem[i].removeEventListener("mouseover", elementOver() );
> }
> }
>
> Adding the listener works but removing it doesn't. I don't understand
> why not nor how to remove the listeners?
>
> Andrew Poulos
My Guess is you're not passing the same "elem" to both functions.
BTW you should use delegation and let the event bubble up to a parent
and then decide which child target the mouse was on from that.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
removeeventlistener Andrew Poulos <ap_prog@hotmail.com> - 2017-10-16 14:29 +1100
Re: removeeventlistener Julio Di Egidio <julio@diegidio.name> - 2017-10-15 21:08 -0700
Re: removeeventlistener Richard Maher <maher_rjSPAMLESS@hotmail.com> - 2017-10-16 13:06 +0800
Re: removeeventlistener Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-16 22:18 +0200
Re: removeeventlistener Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-28 19:48 +0200
Re: removeeventlistener Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-10-28 20:00 +0200
csiph-web