使用Javascript复制DOM中的节点 [英] Copy nodes in DOM using Javascript
本文介绍了使用Javascript复制DOM中的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这种XML文件:
<data>
<First id="FirstOne">
<lines id="Lines">
<Second id= "second" ColorPerVertex='true'></Second>
<third id="third" color ='true'></third>
</lines>
</First>
</data>
我试图复制父节点的所有子节点-行.
I was trying to copy all the childnodes of the parentnode - lines.
这是我尝试过的代码段:
this is the kind of snippet I tried :
var txt=$(xml).find("lines").children();
alert(txt); // to check if it is really does fetch it.
它不会输出包括其属性的所有子项.
it does not output all the children including the attributes of it.
I tried looking into this example here. Even this did not work for me.
有什么办法可以做到?
推荐答案
来自文档 :
jQuery(html [,ownerDocument])
html: A string of HTML to create on the fly. Note that this parses HTML, not XML.
html: A string of HTML to create on the fly. Note that this parses HTML, not XML.
使用 $.parseXML 来创建XML-文档.
Use $.parseXML instead to create the XML-document.
var txt=$($.parseXML(xml)).find("lines").children();
这篇关于使用Javascript复制DOM中的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文