How can I use Javascript to play an HTML5 <video>
?
For example, play the video at a onclick
event.
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();
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With