// console.log(window.innerWidth); if (window.innerWidth > 500) { document.getElementById('c-moved').remove(); } if (window.innerWidth < 500) { document.getElementById('c-orig').remove(); } window.onload = function() { var iframe = document.getElementById('ytvid'); var innerDoc = iframe.contentDocument || iframe.contentWindow.document; // Now you can select elements within the iframe document var elementInsideIframe = innerDoc.getElementById('app'); console.log(elementInsideIframe); }