Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
51
rated 0 times [  58] [ 7]  / answers: 1 / hits: 32181  / 12 Years ago, thu, august 30, 2012, 12:00:00

How can I use Javascript to play an HTML5 <video>?


For example, play the video at a onclick event.


More From » html

 Answers
93

Add an event listener to your play button where it calls videoElem.play()


HTML:


<video id='video'>
<source src="your-video-source.mp4" type="video/mp4">
</video>

<button id='playVid'>Play</button>

Javascript:


document.getElementById('playVid').onclick = function () {
document.getElementById('video').play();
};

[#83328] Wednesday, August 29, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nikoguym

Total Points: 339
Total Questions: 106
Total Answers: 95

Location: Mali
Member since Sat, Feb 12, 2022
2 Years ago
;