## HTML Audio/Video DOM: `waiting` Event
The `waiting` event is a crucial media event in HTML5. It fires when playback stops because the media element (either `
` or ``) has temporarily run out of data and needs to buffer the next frame or segment before resuming.
This event is highly useful for improving user experience (UX) by allowing developers to display loading spinners, buffering indicators, or custom pause overlays when network congestion or slow loading speeds interrupt playback.
---
## Syntax and Usage
You can register the `waiting` event in three different ways: using HTML attributes, using the JavaScript event handler property, or using the `addEventListener()` method.
### 1. In HTML
```html
```
### 2. In JavaScript (Event Handler Property)
```javascript
const mediaElement = document.getElementById("myMedia");
mediaElement.onwaiting = function() {
// Your custom buffering logic here
};
```
### 3. In JavaScript (Event Listener)
```javascript
const mediaElement = document.getElementById("myMedia");
mediaElement.addEventListener("waiting", myScript);
function myScript() {
// Your custom buffering logic here
}
```
---
## Code Examples
### Example 1: Basic Alert on Buffering
This example displays a simple alert message when the video runs out of data and needs to buffer the next frame.
```html
Your browser does not support the video tag.
```
### Example 2: Showing and Hiding a Loading Spinner (Real-World Scenario)
In production, you typically want to show a loading spinner when the media is buffering (`waiting`) and hide it when playback resumes (`playing` or `canplay`).
```html
```
---
## Technical Details
| Feature | Description |
| :--- | :--- |
| **Supported HTML Tags** | ``, `` |
| **Supported JavaScript Objects** | Audio, Video |
| **Bubbles** | No |
| **Cancelable** | No |
---
## Browser Support
The numbers in the table specify the first browser version that fully supports the `waiting` event.
| Event | Chrome | Internet Explorer / Edge | Firefox | Safari | Opera |
| :--- | :--- | :--- | :--- | :--- | :--- |
| **`waiting`** | Yes | 9.0+ | Yes | Yes | Yes |
> **Note:** Internet Explorer 8 and earlier versions do not support the standard `addEventListener()` method. For legacy IE support, use `attachEvent()` or the `onwaiting` property directly.