JSFiddle - React, Tailwind, and code Playground

by kirrrusha

HTML

<button id="add">Add new</button>
    <div id="container">
        <button class="alert">alert!</button>
    </div>

JavaScript

$("button#add").click(function() {
    var el = $('<button class="alert">Alert!</button>');
    el.click(function(){
        alert(2);
    })
    $("button.alert:last").parent().append(el);
    
});
$("div#container").on('click', 'button.alert', function() {
    alert(1);
});