38

I know how to start and stop a video with play() and pause(), but how do I put a video back to the start in HTML5 using javascript? is there a way to move the pointer back to the start?

rom
  • 540
  • 2
  • 5
  • 9

3 Answers3

59

Set the currentTime property back to 0.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 3
    Got it! Thanks for the answer. $('#mov1').get(0).currentTime = 0; – rom Dec 06 '11 at 15:24
  • @startupthekid — Nobody suggested trying to use it on a jQuery object and it isn't a function/method, it's a property holding a number. – Quentin Jan 08 '16 at 09:11
33

To have a proper stop functionality you could do the following:

var video = document.getElementById('vidId');
// or video = $('.video-selector')[0];
video.pause();
video.currentTime = 0;
video.load();

Note: This is the only version that worked for me in chrome using nodejs (meteorjs) in the backend, serving webm, mp4, ogg files

Matyas
  • 13,473
  • 3
  • 60
  • 73
  • 1
    Using `video.play()` after I set the `currentTime` to `0` works as well. What's the reason it must be `video.load()` here? – noob Jul 11 '22 at 01:32
-1

load() will reload video and put it back to start