CKTIS / HTML
onemptied — handle a media resource being emptied
The onemptied attribute specifies JavaScript to run when an emptied event occurs. For audio and video, this event concerns resetting the media resource state, rather than ordinary completion of playback.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
onemptied="JavaScript statements"onemptied is an HTML event handler content attribute for the emptied event. Its value contains JavaScript statements; the event object is available inside the handler as event. It is a global event handler attribute, but audio and video elements are the natural sources of this event.
The browser fires emptied when media resource state is reset. For example, load() queues this event if the previous networkState was not NETWORK_EMPTY. Calling load() on a new, empty element therefore does not guarantee an event. Do not confuse emptied with ended, which indicates reaching the end of playback, or with temporarily lacking data to continue playback.
In JavaScript, instead of the attribute, you can assign a function to media.onemptied or use media.addEventListener('emptied', handler). The event name has no on prefix. Assigning the property again replaces its previous handler; addEventListener allows independent handlers to be registered. A CSP policy can block code in event handler attributes.
The example deliberately dispatches a synthetic emptied event, so it needs no media file or network access. The expected visible output is emptied. This tests handler wiring, not an actual resource reset; dispatching the event does not change the media state.
Examples
<!doctype html>
<meta charset="utf-8">
<title>onemptied</title>
<audio onemptied="document.getElementById('result').textContent = event.type;"></audio>
<output id="result">pending</output>
<script>
const media = document.querySelector('audio');
media.dispatchEvent(new Event('emptied'));
</script>Result
emptied
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.