JSFiddle - React, Tailwind, and code Playground

by klierik

HTML

<div id="iframeWrap"></div>

JavaScript

var videoURLs = [
    "https://www.youtube.com/embed/vSkb0kDacjs",
    "https://www.youtube.com/embed/8-Ixo7QXw_E",
    "https://www.youtube.com/embed/lmc21V-zBq0",
    "https://www.youtube.com/embed/dQiNVk_u0po",
    "https://www.youtube.com/embed/MOg8Cz9yfWg"
]

function videoRandomize(videoURLs) {

    var $iframe = $('<iframe id="youtube" width="560" height="315" src="#" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'),
        $iframeWrap = $("#iframeWrap"),
        url = videoURLs[Math.floor(Math.random() * videoURLs.length)];

    $iframe.attr('src', url);
    $iframeWrap.empty().append($iframe.clone());
}

videoRandomize(videoURLs);