What i do | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What i do

How can i change videos using btn in html ??๐Ÿค”๐Ÿค”

25th Sep 2020, 1:03 PM
Kapish M Kantharia ( available)
Kapish M Kantharia ( available) - avatar
4 Answers
+ 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.
25th Sep 2020, 1:08 PM
๐Ÿ‡ฎ๐Ÿ‡ณOmkar๐Ÿ•‰
๐Ÿ‡ฎ๐Ÿ‡ณOmkar๐Ÿ•‰ - avatar
+ 1
Can u Show ur code?
25th Sep 2020, 2:20 PM
Bas Hogerhuis
Bas Hogerhuis - avatar
+ 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>
25th Sep 2020, 2:22 PM
Kapish M Kantharia ( available)
Kapish M Kantharia ( available) - avatar
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 ๐Ÿ‘
25th Sep 2020, 3:12 PM
๐Ÿ‡ฎ๐Ÿ‡ณOmkar๐Ÿ•‰
๐Ÿ‡ฎ๐Ÿ‡ณOmkar๐Ÿ•‰ - avatar