#11169 closed bug (duplicate)
append does not work i XML document / element
Reported by: | skovenborg | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | manipulation | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
In below javascript - why does the second alert not display "tryagain"
$(function() {
var xml = "<aaa><bbb>try</bbb></aaa>"; var doc = $.parseXML(xml); $(doc).append("<ccc>tryagain</ccc>"); $("div").append("<ccc>tryagain</ccc>"); alert($(doc).find("bbb").text()); alert($(doc).find("ccc").text()); alert($("div").find("ccc").text());
});
Here a link to jsfiddle working example: http://jsfiddle.net/28966268/r7MgY/11258/embedded/result/
I'm using jquery 1.7.1 Firefox 9.0.1 Windows 7 Professionel
Change History (4)
comment:1 Changed 11 years ago by
Component: | unfiled → manipulation |
---|---|
Priority: | undecided → low |
Resolution: | → duplicate |
Status: | new → closed |
comment:2 Changed 11 years ago by
comment:3 Changed 11 years ago by
Hi I first found the solution to created the appendChild jquery function
jQuery.fn.appendChild = function(ns, nodeName) {
var dom = document.implementation.createDocumentNS(ns, nodeName, null); var element=dom.createElement(nodeName); this.append(element);
};
But nice to know about the difference between nodeType 1 and 9 - Now I created the appenXMLfragment function
jQuery.fn.appendXMLfragment = function(xml) {
var node = $.parseXML(xml); this.append($(":first", node));
};
comment:4 Changed 11 years ago by
sorry jQuery.fn.appendChildNS = function(ns, nodeName) { var dom = document.implementation.createDocument(ns, nodeName, null); var element=dom.createElement(nodeName); this.append(element);
};
Duplicate of #9960.