The .replaceWith()
function accepts a function which returns the new HTML to replace that element with, so you could do:
$(this).closest('.ui-btn-text').find("a[data-rel='popup']").replaceWith(function() {
return $(this).html();
});
It's important to note that this
inside the function passed to .replaceWith()
is different to this
at the beginning of the line; inside the function it refers to the current matched element being replaced by the new HTML.