Click here to Skip to main content
15,850,360 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having a hard time on how to create a div around a iframe without interrupting the iframe playing the YouTube video I know the code is wrong for this situation but i'm just clueless how I can do this.

This is my code

<style>
    button{
     margin-top: 25px;
      display: block;
    }
    </style>
    
    <script>
    document.addEventListener('DOMContentLoaded',function(){
    
    document.querySelector('button').addEventListener('click',addADivAroundAIframe);
    
    function addADivAroundAIframe() { 

            var iframe= document.querySelector('iframe');
            var parent = iframe.parentNode;
            var div= document.createElement('div');

            parent.replaceChild(div,iframe);

            div.appendChild(iframe);
      
      }
    
    });
    </script>
    
    <iframe src='https://www.youtube.com/embed/m1jY2VLCRmY'></iframe>
    
    <button>Generate</button>


What I have tried:

Google, other help sites, books
Posted
Comments
David_Wimbley 2-Dec-18 23:07pm    
Why not just wrap the iframe in a div ahead of time?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900