Skip to main content

Bug Tracker

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 sindresorhus comment:1

component: unfiledmanipulation
priority: undecidedlow
resolution: → duplicate
status: newclosed

Changed January 31, 2012 02:23PM UTC by sindresorhus comment:2

Duplicate of #9960.

Changed January 31, 2012 09:09PM UTC by anonymous 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 anonymous 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);

};