# Remove Event Listners in Cesium

**URL:** <https://community.cesium.com/t/remove-event-listners-in-cesium/17927>\
**Category:** CesiumJS\
**Created:** [March 29, 2022, 10:02pm UTC](https://community.cesium.com/t/remove-event-listners-in-cesium/17927 "2022-03-29T22:02:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![C00der](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/c00der/32/8670_2.png) [@C00der](https://community.cesium.com/u/C00der)\
**Post date:** [March 29, 2022, 10:02pm UTC](https://community.cesium.com/t/remove-event-listners-in-cesium/17927/1 "2022-03-29T22:02:59Z")

</div>

I looked around quite a bit to find out the correct way to remove event listners in Cesium. I believe the confusion I have is around whether to treat Cesium events as regular DOM events or as Cesium specific ones (due to a lack of knowledge about events in general in javascript). I am creating a screen space event like below:

```auto
    var handler = new Cesium.ScreenSpaceEventHandler(canvas);

    handler.setInputAction(function (m) {
        var picked = scene.pick(m.endPosition);
        if (Cesium.defined(picked) && picked.id === someEntity) {
            labelEntity.label.show = true;
        } else {
            labelEntity.label.show = false;
        }
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

```

My question is, how can I remove this event listner? Does `handler.destroy()` remove all the event listners associated with handler, or do I specifically have to remove event listners by pointing to the cesium map DOM element and calling `removeEventListner` on it? If that’s the case, what parameters should be passed on to `removeEventListner` ?

---

<div class="post-metadata">

**Author:** ![onsummer](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/onsummer/32/5408_2.png) [@onsummer](https://community.cesium.com/u/onsummer)\
**Post date:** [March 30, 2022, 2:12pm UTC](https://community.cesium.com/t/remove-event-listners-in-cesium/17927/2 "2022-03-30T14:12:53Z")

</div>

You can remove event listener by this:

```nohighlight
handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE)

```

---

<div class="post-metadata">

**Author:** ![C00der](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/c00der/32/8670_2.png) [@C00der](https://community.cesium.com/u/C00der)\
**Post date:** [March 30, 2022, 3:32pm UTC](https://community.cesium.com/t/remove-event-listners-in-cesium/17927/3 "2022-03-30T15:32:51Z")

</div>

Thank you @onsummer . If I want to remove all the event listeners attached to the handler and also the handler itself, will it be fine to do handler.destroy()? Will that guarantee that those listeners are not going to be present in the cesium view from which I removed the events?

---

<div class="post-metadata">

**Author:** ![onsummer](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/onsummer/32/5408_2.png) [@onsummer](https://community.cesium.com/u/onsummer)\
**Post date:** [March 30, 2022, 3:56pm UTC](https://community.cesium.com/t/remove-event-listners-in-cesium/17927/4 "2022-03-30T15:56:35Z")

</div>

Yes.

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [April 1, 2022, 5:41pm UTC](https://community.cesium.com/t/remove-event-listners-in-cesium/17927/5 "2022-04-01T17:41:42Z")

</div>

Hi @onsummer,

Thanks for the suggestion! I think `removeInputAction` is the perfect method for this use case 👍

-Sam
