+ 2
What i do
How can i change videos using btn in html ??🤔🤔
4 Réponses
+ 1
Add 'click' event listener to button. In callback function set src attribute of video element to url of new video.
You should show what have you tried so far to solve this problem. Link your code in description.
+ 1
Can u Show ur code?
+ 1
<video controls autoplay loop>
<source src="http://www.sololearn.com/uploads/video.mp4" type="video/mp4">
<source src="http://www.sololearn.com/uploads/video.ogg" type="video/ogg">
Video is not supported by your browser
</video>
//kapish//
<button id=day1><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQvEfw6Hd-bZzGfqyhkd46DKeTAPVsp0Eulfg&usqp=CAU"/></button>
<script>
var btn = document.getElementById("day1");
btn.addEventListener("click", myFunction);
function myFunction() {
;
}
</script>
0
Kapish M Kantharia (Always Active) ,
Good 👍.
In myFunction(), Just retrieve the video element using a DOM method for example using querySelector()
const video = document.querySelector('video');
and then change its src attribute
video.src = "http://www.sololearn.com/uploads/video.mp4";
Note: I'm using same url as original video but you should change it with url of other video.
Good luck 👍