【问题标题】:remove B elements add them at the end of the doment load删除 B 元素在 doment 加载结束时添加它们
【发布时间】:2011-12-16 03:09:10
【问题描述】:

我对使用文本节点在 div 中查找和换行文本的 jquery 脚本有疑问。

它在一开始就忽略了<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>

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

编辑:抱歉不清楚。以上是我要修复的。即:

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

</div>

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

【问题讨论】:

    标签: jquery textnode


    【解决方案1】:

    转这个:

    <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);
    

    【讨论】:

    • 我可以.append那个div吗?
    • @uriah - 可能 - 我不确定你的意思。上面的代码获取第一个 之后的所有内容,并将它们包装在 class'description' 的 div 中——这不是你想要的吗?
    • 不,我想在创建 .description 之后将其移至 .description。对不起
    猜你喜欢
    • 2020-11-08
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 2013-01-15
    相关资源
    最近更新 更多