Change video tag source url using Javascript
You want change <video> tag's <source></source> src when click on button in HTML and Javascript.
Here is the code with example
<video autoplay="autoplay" control="false" id="howto" loop="loop" muted="muted" playsinline="playsinline" poster="POSTER IMAGE URL" preload="metadata">
<source asrc="MP4 URL" id="howtosource" type="video/mp4"></source>
<img src="PSTER IMAGE URL" />
</video>
<a class="button" href="#" onclick="dook();">▷ Play Video Now</a>
<script>
const dook = () => {
const howto = document.getElementById("howto");
const howtosource = document.getElementById("howtosource");
const newSource = howtosource.getAttribute("asrc");
howtosource.setAttribute("src", newSource); h
owto.load();
howto.play();
};
</script>
0 comments:
Post a Comment