I try to toggle between two youtube videos. This is my try:
const videoIDs = ["puAoFjGcQZI", "KEmBRLr3jsc"];
let currentVideoIndex = 0;
const videoElement = html`<iframe width="560" height="315" src="https://www.youtube.com/embed/${videoIDs[currentVideoIndex]}" frameborder="0" allowfullscreen></iframe>`;
const switchButton = html`<button>Switch Video</button>`;
switchButton.addEventListener("click", () => {
currentVideoIndex = (currentVideoIndex + 1) % videoIDs.length;
videoElement.src = `https://www.youtube.com/embed/${videoIDs[currentVideoIndex]}`;
});
html`${videoElement}${switchButton}`
This doesnt work. Could anybody help me? Thank you!