JSFiddle - React, Tailwind, and code Playground
HTML
<div id="container">
<div id="field">hello there:)</div>
</div>
JavaScript
$(function() {
$('#container').on('click', '#field', function() {
if (!$(this).is('input')) {
$(this).replaceWith("<input type=\"text\" name=\"fname\" id=\"field\" value=\"" + $(this).text() + "\">");
}
});
$('#container').on('mouseout', '#field', function() {
if ($(this).is('input')) {
if ($(this).val() != '') {
$(this).replaceWith("<div id=\"field\">" + $(this).val() + "</div>");
}
else {
$(this).replaceWith("<div id=\"field\">hello there:)</div>");
}
}
});
});