For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Saturday, November 30, 2024

Change video tag source url using javascript

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>  
Share:

0 comments:

Post a Comment

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip