The onplay property of the GlobalEventHandlers mixin is the EventHandler for processing play events.


element.onplay = handlerFunction;
var handlerFunction = element.onplay;

handlerFunction should be either null or a JavaScript function specifying the handler for the event.


<p>This example demonstrates how to assign an "onplay" event to a video element.</p>

<video controls onplay="alertPlay()">
  <source src="mov_bbb.mp4" type="video/mp4">
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.

<p>Video courtesy of <a href="" target="_blank">Big Buck Bunny</a>.</p>

function alertPlay() {
  alert("The video has started to play.");


Specification Status Comment
HTML Living Standard
The definition of 'onplay' in that specification.
Living Standard

Browser compatibility

BCD tables only load in the browser

See also