JSFiddle - React, Tailwind, and code Playground

HTML

<script>
function createElementMY(){
    var doc = document.getElementById('container');
    
    var ifrDoc = doc.contentDocument;
    
    
    var elem = ifrDoc.createElement("div");
    elem.textContent = 'Test';
    ifrDoc.body.appendChild(elem);
}
</script>
<iframe id="container" src="data:text/html,rawr"></iframe>
<button onclick="createElementMY()">Click me!</button>

CSS

#container{
    width: 100%;
    height:300px;
    overflow: hidden;
}

JavaScript

function rawr(){
    var doc = document.getElementById('container');
    
    var ifrDoc = doc.contentDocument;
    
    alert(ifrDoc)
}