var modal = document.createElement('div'); var buttons = document.getElementsByClassName('iframe'); //var modal_inner = document.createElement('div'); // //modal.className = "modal"; modal.id = 'modal'; document.body.prepend(modal); /*modal_inner.className = "modal-inner"; document.body.modal.innerHTML = modal_inner;*/ // for(var i = 0; i < buttons.length; i++) { var button = buttons[i]; button.onclick = function() { //alert("hello"); var url = this.href; modal.classList.add('show'); modal.innerHTML = ''; //console.log(url); // return false; }; } document.addEventListener("click", function (e) { const target = e.target; if (target instanceof HTMLElement) { if (target.id === 'modal-close') { //alert('Hi'); document.getElementById('modal').classList.remove('show'); } } });