删除B元素在文档加载结束时添加它们

时间:2011-12-16 03:09:10

标签: jquery textnode

我有一个jquery脚本的问题,使用文本节点查找并在div中包装文本。

一开始就忽略了<b>个元素。但不是在任何纯文本之后。

<b>Bold introduction</b>
content content content <b>content</b> content

对此:

<b>Bold introduction</b>

<div class="description">
content content content <b>content</b> content

</div>

我能想到的一个解决方案是删除<b>元素,然后在文本节点脚本触发后重新插入它们。有可能吗?感谢

编辑:抱歉不清楚。以上是我想解决的问题。即:

<div class="description">
<b>Bold introduction</b>
content content content <b>content</b> content

</div>

这是文本节点脚本jsfiddle的错误 js fiddle

1 个答案:

答案 0 :(得分:0)

转过来:

<b>Bold introduction</b>
content content content <b>content</b> content

进入这个:

<b>Bold introduction</b>

<div class="description">
content content content <b>content</b> content

</div>

我想你想要

$("b:first").nextAll().wrapAll("<div class='description' />");

修改

如果你想这些元素移动到描述div中,那么应该这样做

var toMove = $("b:first").nextAll().remove();
$(".description").append(toMove);