JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<p>1</p>
</div>
<div>
<p>1</p>
<p>2</p>
</div>
JavaScript
$('div').each(function () {
var elm= $(this).find('p').eq(1);
if(elm.length==0)
{
$(this).find('p').after('test');
}
else
{
elm.html('test')
}
});