JSFiddle - React, Tailwind, and code Playground

by JAAulde

HTML

<div id="cards">
    <p class="elementWhichCanBeReplacedDuringLoad">Click Me!</p>
</div>

<button id="runreplace">Replace Nodes</button>

JavaScript

//Delegate clicks of elementWhichCanBeReplacedDuringLoad elements to #cards
$('#cards').on('click', '.elementWhichCanBeReplacedDuringLoad', function (e) {
    alert('Delegated click happened!');
});

// Not relevant to your question, just setting up the content replacement
$('#runreplace').one('click', function () {
    $(this).remove();

    $('#cards')
        .empty()
        .append(
            $('<span/>')
                .addClass('elementWhichCanBeReplacedDuringLoad')
                .text('Click me too!')
        );
});