---
title: JavaScript Event Handling
slug: develop/javascript-event-handling
docTags: 
createdAt: 2025-03-11T07:07:19.526Z
---

## AddEventListener

`addEventListener()` is a common BrightSign method that is used to listen for an event.

### Syntax:

```javascript
target.addEventListener(type, listener);
```

- `type` <font color="#6B21A8">string</font>: Specifies the type of event to listen for
- `listener` <font color="#6B21A8">function</font>: The object to be notified when the event (of the specified `type`) happens 

## RemoveEventListener

`removeEventListener()`is a common BrightSign method that is used to remove an event listener.

### Syntax:

```javascript
target.removeEventListener(type, listener);
```

- `type` <font color="#6B21A8">string</font>: Specifies the type of event to listen for
- `listener` <font color="#6B21A8">function</font>: The object to be notified when the event (of the specified `type`) happens 

## Example

```javascript
function GPIOcontrolDown(msg){

    console.log(JSON.stringify(msg)); 
    console.log(" GPIO : " + msg.detail)
}

// to add an event listener for the "controldown" GPIO event

control_port.addEventListener("controldown", GPIOcontrolDown);

// to remove the "controldown" GPIO event listener

control_port.removeEventListener("controldown", GPIOcontrolDown);
```

