Javascript 如何更改html div而不影响JQuery中的内部div

Javascript 如何更改html div而不影响JQuery中的内部div,javascript,jquery,Javascript,Jquery,如何在html中更改Div内的html而不影响Jquery中父Div内的内部Div 到目前为止,我有: HTML: 唯一的问题是,如果html上没有标记,它可以正常工作,但例如,在或等之后,它不会改变 单向: $('#div_to_change').contents().each(function () { //select only nodes with type 3 and having a node value to ignore empty lines, format chars

如何在html中更改Div内的html而不影响Jquery中父Div内的内部Div

到目前为止,我有:

HTML:

唯一的问题是,如果html上没有标记,它可以正常工作,但例如,在

等之后,它不会改变

单向:

$('#div_to_change').contents().each(function () {
   //select only nodes with type 3 and having a node value to ignore empty lines, format chars etc
    if(this.nodeType == 3 
        && $.trim(this.nodeValue) 
        )
    {
        $(this).replaceWith("changed text")
    }
});

或者只使用过滤器:

$('#div_to_change').contents().filter(function () {
    return (this.nodeType == 3 
            && $.trim(this.nodeValue) 
           )
}).replaceWith("changed text");

卓越!由于某种原因,我的应用程序中的第二个不起作用,但第一个很有魅力!非常感谢您对PSL的帮助+1 XDHi,我刚发现一个bug,可以修复吗@vashzero什么是错误我没有得到它。嗨,如果我之前没有解释,我很抱歉,但这里是这样的:结果是:Ingrear Texto aqí123更改的文本不应该更改不应该更改的文本,结果应该是:更改的文本不应该更改没有“Ingrear Texto aqí123”,因为它是html的一部分,应该被修改。@vashzero您的意思是输出应该删除
Ingrear Texto aqí123
?但我以为您想更改免费漫游textx。此文本在字体标记内?
$('#div_to_change').contents().each(function () {
   //select only nodes with type 3 and having a node value to ignore empty lines, format chars etc
    if(this.nodeType == 3 
        && $.trim(this.nodeValue) 
        )
    {
        $(this).replaceWith("changed text")
    }
});
$('#div_to_change').contents().filter(function () {
    return (this.nodeType == 3 
            && $.trim(this.nodeValue) 
           )
}).replaceWith("changed text");