JSFiddle - React, Tailwind, and code Playground
HTML
<p class="ptest1"></p><br>
<p class="ptest1"></p><br>
<p class="ptest2"></p><br>
<p class="ptest2"></p><br>
<p class="ptest3"></p><br>
JavaScript
$().ready(function(){
function create(){
return $('<div style="cursor:pointer">Click</div>')
.click( function(){ alert('click'); } );
}
//insertBefore is OK. Events and data are cloned.
create().insertBefore($('.ptest1'));
//before don't work as expected.
//The events and data aren't properly cloned.
//perhaps this happen to "after" too.
$('.ptest2').before(create());
//with only one element
//the click event is binded normaly - no cloning
$('.ptest3').before(create());
});