How to change the autoplay attribute? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to change the autoplay attribute?

I'm using autoplay in my code, but I want the video to stop playing as soon as someone pushes a button. I've set the autoplay attribute to true in HTML, but how can I change it back to false in JavaScript? (or HTML if possible) This is my code: https://code.sololearn.com/WdwSg2Um7KD2/?ref=app It's about the link with id="music"

30th May 2017, 6:16 PM
Maart
Maart - avatar
4 Answers
+ 14
video.removeAttribute("autoplay"); or video.autoplay = "false"||"off"; video.setAttribute("autoplay","..."); //does any work??
30th May 2017, 6:23 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 14
iframe.src = "https://www.youtube.com/embed/7JIdJLkJ0S4?autoplay=0"; //maybe change the 1 from the end of src to 0?
30th May 2017, 6:28 PM
Valen.H. ~
Valen.H. ~ - avatar
0
Nope :/ It's specified as iframe though, not sure if that matters
30th May 2017, 6:27 PM
Maart
Maart - avatar
0
Nope, if I change it in HTML, it's changed from the beginning, but I want it only to stop after pushing the button and if I change it in JS I get errors
30th May 2017, 6:38 PM
Maart
Maart - avatar