Javascript 查找所有INS,将文本节点包装到INS标记中,并使用新的del标记查找相应类名的del

Javascript 查找所有INS,将文本节点包装到INS标记中,并使用新的del标记查找相应类名的del,javascript,jquery,html,Javascript,Jquery,Html,我有这个html <html> <head></head> <body> <div class="para"> <ins>A computer is a</ins> popular <del>new</del><ins> device</ins> </div> <div class="para"&g

我有这个html

<html>
    <head></head>
<body>
    <div class="para">
        <ins>A computer is a</ins> popular <del>new</del><ins> device</ins>
    </div>

    <div class="para">
        <ins>Stored programs</ins><del>required the re-wiring and re-structuring of the machine.</del>
    </div>
    <div class="para">
        <ins>Integrated </ins>new<del>circuits</del><ins>System </ins>
    </div>
</body>
</html>

请帮助我解决此问题

您应该能够使用
document.querySelectorAll('.para')
获取它们的数组。然后循环他们的目标是他们的孩子

不过,它不是jquery,不确定你是死心塌地地使用jquery还是喜欢香草口味。

你可以使用
.each()
.contents()
.filter()
来获取
中的
文本节点。para
元素具有
。parentElement
等于当前
元素的
。para
元素
.appendTo()
将选定的
#text
节点附加到当前
元素中的第一个
ins
元素中

$(“.para”)。每个(函数(索引,元素){
$(this.contents().filter(function()){
返回this.nodeName==“#text”&&this.parentElement==元素
}).appendTo($(“ins:first”,元素))
})

计算机是一种流行的新设备
存储程序需要对机器进行重新布线和重新构造。
集成电路系统
为什么
“popluar”
不在
html
的预期结果中?另外,结果中的第一个
.para
要么缺少开头
,要么有额外的
<html> 
<head></head>
<body>
    <div class="para">
        <ins>A computer is a popular</ins><del>new</del><ins> device</ins>
    </div>

    <div class="para">
        <ins>Stored programs</ins><del>required the re-wiring and re-structuring of the machine.</del>
    </div>
    <div class="para">
        <ins>Integrated new</ins><del>circuits</del><ins>System </ins>
    </div>
</body>
</html>
var unit = $('.para');
$.each(unit, function(){
   var nodes = $(this).find('ins');
})