Remove text with jQuery
Solution 1:
Using the answer from this question:
$(elem)
.contents()
.filter(function() {
return this.nodeType == 3; //Node.TEXT_NODE
}).remove();
Solution 2:
First, you can wrap them with dummy spans:
$("body").contents()
.filter(function(){ return this.nodeType != 1; })
.wrap("<span class='orphan'/>");
Now you can remove them easily:
$('span.orphan').remove();
Solution 3:
fwiw..
<div class="parent-element">
<p>This is some text</p>
This is "unwrapped" text //to be removed
<span>some more text</span>
</div>
via CSS:
.parent-element { font-size: 0px; }
.parent-element p { font-size: 12px; }
.parent-element span { font-size: 14px; }