JSFiddle - React, Tailwind, and code Playground
by ShankarSangoli
HTML
<p>
<span class="target">Change me <a class="changeme" href="#">now</a></span>
</p>
<p>
<span class="target2"><a class="changeme" href="#">now</a></span>
</p>
JavaScript
$(document).ready(function() {
var $textNode, $parent;
$('.changeme').on('click', function(){
$parent = $(this).parent();
$textNode= $parent.contents().filter(function() {
return this.nodeType == 3;
});
if($textNode.length){
$textNode.replaceWith('Content changed')
}
else{
$parent.prepend('New content');
}
});
});