JSFiddle - React, Tailwind, and code Playground

by Michael Geary

HTML

<iframe frameborder="0" height="100" id="myframe" scrolling="no" width="200"></iframe>

JavaScript

// Get the iframe element
var $frame = $('#myframe'),
    frame = $frame[0],
    framewin = frame.contentWindow,
    framedoc = framewin.document;

// Populate the iframe with a test page
framedoc.write(
    '<!DOCTYPE html>',
        '<html>',
        '<head>',
            '<title>my frame</title>',
        '</head>',
        '<body>',
            '<h2 style="border:1px solid red;">',
                'Click Me!',
            '</h2>',
        '</body>',
    '</html>'
);

$(framedoc).find('h2').click(function(){
    alert('Clicked h2');
});