MDN self-hosted library · e01.org

HTMLMediaElement: error event

HTML DOM

HTML DOM

The error event is fired when the resource could not be loaded due to an error (for example, a network connectivity problem).

This event is not cancelable and does not bubble.

Syntax

Use the event name in addEventListener():

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

Alternatively, assign to the event handler property of the interface:

onerror = (event) => { }

Event type

A generic Event.

Examples

const video = document.querySelector("video");
const videoSrc = "https://path/to/video.webm";

video.addEventListener("error", () => {
  console.error(`Error loading: ${videoSrc}`);
});

video.setAttribute("src", videoSrc);

Specifications

Browser compatibility

See also

  • HTMLAudioElement
  • HTMLVideoElement
  • audio
  • video