Ticket #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: | ||
| Blocking: | Blocked by: |
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
comment:1 Changed 16 months ago by sindresorhus
- Priority changed from undecided to low
- Resolution set to duplicate
- Status changed from new to closed
- Component changed from unfiled to manipulation
comment:3 Changed 16 months ago by anonymous
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));
};
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
