JSFiddle - React, Tailwind, and code Playground
HTML
<a href="javascript:void(0);" class="edit" data-id="123">Edit</a>
<button>Reset</button>
JavaScript
function replaceElement(el, tagName) {
var attrs = {
text: el.innerHTML
};
$.each(el.attributes, function() {
attrs[this.nodeName] = this.nodeValue;
});
$(el).replaceWith($("<" + tagName + " />", attrs));
}
$("body").on("click", "a.edit", function() {
replaceElement(this, "span");
});
$("button").on("click", function() {
replaceElement($("span")[0], "a");
});