JSFiddle - React, Tailwind, and code Playground
HTML
<div class="doit" style="color:green">This text should be replaced (a)</div>
<div class="doit2" style="color:red">This text should be replaced (b)</div>
JavaScript
a();
function a() {
$('.doit').text('Text was replaced (a)');
}
if ($('.doit2').length) {
b();
function b() {
$('.doit2').text('Text was replaced (b)');
}
}