How to change the source on the HTML video tag with JavaScript?

Spread the love

Sometimes, we want to change the source on the HTML video tag with JavaScript.

In this article, we’ll look at how to change the source on the HTML video tag with JavaScript.

How to change the source on the HTML video tag with JavaScript?

To change the source on the HTML video tag with JavaScript, we set its src property.

For instance, we write

const video = document.getElementById("video");
video.src = url;
video.play();

to get the video element with getElementById.

Then we set its src property to the video url.

And then we call play to play it.

Conclusion

To change the source on the HTML video tag with JavaScript, we set its src property.

Leave a Reply

Your email address will not be published. Required fields are marked *