MIDIPort: statechange event - Web APIs | MDN

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js

addEventListener("statechange", (event) => { })

onstatechange = (event) => { }

Event type

A MIDIConnectionEvent. Inherits from Event.

Event MIDIConnectionEvent

Event properties

MIDIConnectionEvent.port Read only

Returns a reference to a MIDIPort instance for a port that has been connected or disconnected.

Example

In the following example the current MIDIPort.state is logged each time it changes.

js

port.onstatechange = (event) => {
  console.log(port.state);
};

Specifications

Specification
Web MIDI API
# dom-midiport-onstatechange

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.