AudioTrackList: change event

The change event is fired when an audio track is enabled or disabled, for example by changing the track's enabled property.

This event is not cancelable and does not bubble.

Syntax

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

js

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

onchange = (event) => { }

Event type

A generic Event.

Examples

Using addEventListener():

js

const videoElement = document.querySelector("video");
videoElement.audioTracks.addEventListener("change", (event) => {
  console.log(`'${event.type}' event fired`);
});

// changing the value of `enabled` will trigger the `change` event
const toggleTrackButton = document.querySelector(".toggle-track");
toggleTrackButton.addEventListener("click", () => {
  const track = videoElement.audioTracks[0];
  track.enabled = !track.enabled;
});

Using the onchange event handler property:

js

const videoElement = document.querySelector("video");
videoElement.audioTracks.onchange = (event) => {
  console.log(`'${event.type}' event fired`);
};

// changing the value of `enabled` will trigger the `change` event
const toggleTrackButton = document.querySelector(".toggle-track");
toggleTrackButton.addEventListener("click", () => {
  const track = videoElement.audioTracks[0];
  track.enabled = !track.enabled;
});

Specifications

Specification
HTML Standard
# event-media-change
HTML Standard
# handler-tracklist-onchange

Browser compatibility

BCD tables only load in the browser

See also