ontimeupdate event

Occurs to indicate the current playback position.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section Explorer 9



Event Property object.ontimeupdate = handler;
addEventListener Method object.addEventListener("timeupdate", handler, useCapture)


Event information



Event handler parameters

handler [in]

Type: function

Event handler object.

Standards information


Use the currentTime property to retrieve the current playback position. For the total length of the audio or video clip, use duration.

To invoke this event, do one of the following:

  • Play the video.
  • Move the position indicator on the playback controls.
Note  This event is fired approximately four times a second.


This example shows how to use the timeupdate event and the currentTime property to track the elapsed time while a video plays. See the example online.

<!DOCTYPE html>
    <title>Simple Video Example</title>
      <!-- Uncomment the following tag when developing on a local or intranet computer -->
      <!-- <meta http-equiv-'X-UA-Compatible' content="ie9" />  -->        
<video id="video1" >
   HTML5 video is not supported
</video><br />

<input type="text" id="videoFile" style="width:600px" value="http://ie.microsoft.com/testdrive/ieblog/2011/nov/pp4_blog_demo.mp4"/>
  <!-- Button width set so overall size doesn't change when we toggle the label -->
  <button id="playButton" style="width: 80px" >Play</button>
  <div >Elapsed Time: <span id="timeDisplay"></span></div>


     var oVideo = document.getElementById("video1");      //video element
     var button = document.getElementById("playButton");
     var display = document.getElementById("timeDisplay");

     //  Capture time changes and display current position
     oVideo.addEventListener("timeupdate", function () {
       display.innerText = oVideo.currentTime.toFixed(2) ;
     }, false);

     button.addEventListener("click", function () {
       //  toggle between play and pause based on the paused property
       if (oVideo.paused) {
         var oInput = document.getElementById('videoFile');   //text box
         if (oInput.value) {
           //  only load a video file when the text field changes
           if (oInput.value != oVideo.src) {
             oVideo.src = oInput.value;
       } else {
     }, false);

     // Capture the play event and set the button to say pause
     oVideo.addEventListener("play", function () {
       button.innerHTML = "Pause";
     }, false);

     // Capture the pause event and set the button to say play
     oVideo.addEventListener("pause", function () {
       button.innerHTML = "Play";
     }, false);


See also

How to use HTML5 to play video files on your webpage
How to use HTML5 to Add an Audio Player to your Webpage
Make your videos accessible with Timed Text Tracks