I have some HTML like this:
<div>TEXT
<span>SPAN</span>
<a href="">LINK</a>
</div>
I would like to remove the contents of the elements, usually I would do something like this:
$('*').empty();
or
$('*').contents().empty();
This however will remove/empty the first span and its content which is the div and link. What can I do to preserve the elements while emptying them? So the end result would be:
<span>
<div></div>
<a href=""></a>
</span>
Please note I'm looking for something 'universal' that can be applied to any HTML. The above is just an example, in reality the HTML structure would contain more data.