YouTip LogoYouTip

Event Onplay

## HTML DOM onplay Event The `onplay` event occurs when an audio or video element has been started or is no longer paused (i.e., when the playback begins or resumes after a pause). --- ## Definition and Usage The `onplay` event is triggered when the media (audio or video) starts playing. This can happen when: * The media is loaded and starts playing for the first time. * The user clicks the "Play" button after pausing. * The media is played programmatically using the `.play()` method. **Tip:** The opposite of the `onplay` event is the `onpause` event, which fires when the media is paused. --- ## Browser Support The numbers in the table specify the first browser version that fully supports this event. | Event | Chrome | Internet Explorer / Edge | Firefox | Safari | Opera | | :--- | :--- | :--- | :--- | :--- | :--- | | **onplay** | Yes | 9.0 | Yes | Yes | Yes | --- ## Syntax You can register the `onplay` event in three ways: ### 1. In HTML ```html ``` ### 2. In JavaScript (DOM Property) ```javascript object.onplay = function() { myScript(); }; ``` ### 3. In JavaScript (Event Listener) ```javascript object.addEventListener("play", myScript); ``` *Note: The event name is `"play"` when using `addEventListener()`, but the property name is `onplay` when used as an inline attribute or DOM property.* --- ## Technical Details | Property | Value | | :--- | :--- | | **Bubbles** | No | | **Cancelable** | No | | **Event Type** | Event | | **Supported HTML Tags** | `
← Event OnplayingEvent Onloadeddata β†’