AudioTrackList: change event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
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 # event-media-change |
HTML # handler-tracklist-onchange |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
change event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- User must explicitly enable this feature.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
See also
- Related events:
addtrack
,removetrack
- This event on
VideoTrackList
targets:change
- Media Capture and Streams API
- WebRTC API