JSFiddle - React, Tailwind, and code Playground

JavaScript

text = "mytext"
html = "<div><p><span></span></p></div>"

newHtml = $(html);
newHtml.find('*:last').text(text);

console.log(newHtml.get(0));