我有一个脏 HTML,看起来像这样
示例1:
<div>
somedirtytexthere.
<h1>header 1</h1>
<p>ok this text is cool</p>
</div>
示例2:
<div>
somedirtytexthere.
<h1>header 1</h1>
<p>ok this text is cool</p>
but this text is ALSO cool
</div>
我想使用 jQuery 删除 div
第一个子标签前面的每个(未包含的)文本元素。
最佳答案
$("div")
.contents()
.filter(function () {
return this.nodeType === 3;
}).first().remove();
关于jquery - 如何删除第一个标签之前未包含的脏文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19351179/