Side navigation
#11169 closed bug (duplicate)
Opened January 12, 2012 09:44PM UTC
Closed January 31, 2012 02:23PM UTC
Last modified January 31, 2012 09:11PM UTC
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
Attachments (0)
Change History (4)
Changed January 31, 2012 02:23PM UTC by comment:1
component: | unfiled → manipulation |
---|---|
priority: | undecided → low |
resolution: | → duplicate |
status: | new → closed |
Changed January 31, 2012 09:09PM UTC by comment:3
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));
};
Changed January 31, 2012 09:11PM UTC by comment:4
sorry
jQuery.fn.appendChildNS = function(ns, nodeName) {
var dom = document.implementation.createDocument(ns, nodeName, null); var element=dom.createElement(nodeName); this.append(element);
};