Sometimes, we want to change source on HTML5 video tag with JavaScript.
In this article, we’ll look at how to change source on HTML5 video tag with JavaScript.
How to change source on HTML5 video tag with JavaScript?
To change source on HTML5 video tag with JavaScript, we an set the src
property of the video element.
For instance, we write
const changeSource = (url) => {
const video = document.getElementById("video");
video.src = url;
video.play();
};
to define the changeSource
function.
In it, we get the video with getElementById
.
And then we set the src
property of the video
element to the url
to change the video source.
Conclusion
To change source on HTML5 video tag with JavaScript, we an set the src
property of the video element.