Dynamically change the video id on youtube

六眼飞鱼酱① 提交于 2019-12-06 02:20:48

Not quite sure what you are trying to create, but this might head you into the right direction.

You can reload the specific element in a kind of hacky way using this code

function reload(vidId){ <-- Added a parameter
    var container = document.getElementById("youtube-audio");
    container.setAttribute("data-video", vidId); <-- Added line to change data-video
    var content = container.innerHTML;
    container.innerHTML= content;
}

And then add this to your HTML

<button onclick="reload('8IYzyTYucKQ')">Reload</button> <-- Added the parameter to what the `data-video` should be changed
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!