The GlobalEventHandlers.onplayproperty sets and returns the event handler for the play event that is fired when playback has begun.


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

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


<!DOCTYPE html>

<title>onplay event example :</title>

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

<video controls onplay="myFunction()">
  <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="http://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>

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



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

Browser compatibilityUpdate compatibility data on GitHub

Chrome Edge Firefox Internet Explorer Opera Safari
Basic support Yes ? 3.5 ? ? ?
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes ? 4 ? ? ?

See also

Information on working with event handlers

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.