JSFiddle - React, Tailwind, and code Playground

HTML

<h2></h2>
    <button>generate new element</button>

JavaScript

var counter = 0;

$("button").click(function() {
    $("h2").append("<p class='test'>click me " + (++counter) + "</p>")
});

// With on():

$("h2").on("click", "p.test", function(){
    alert(this.innerText);
});