JSFiddle - React, Tailwind, and code Playground

HTML

<p>Click on this window (but not on the button) and I'll alert. Then click the button below, and try again.</p>

<p><input type="button" id="writeBtn" value="run document.write()" /></p>

CSS

body {
    margin: 20px;
}

p {
    margin-bottom: 20px;
}

JavaScript

var doAlert = function(event) {
    alert('YOU CLICKED!');
};

window.addEventListener('click', doAlert, false);

$(function() {
    $('#writeBtn').click(function(event) {
        window.removeEventListener('click', doAlert, false);
        document.write('<p>I am a new page. Now try clicking on the window.... Nada....</p>');
        window.addEventListener('click', doAlert, false);
    });
});