JSFiddle - React, Tailwind, and code Playground

by jszz

HTML

<h2></h2>
<button>generate 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).text());
});