Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#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 7 years ago by sindresorhus

Component: unfiledmanipulation
Priority: undecidedlow
Resolution: duplicate
Status: newclosed

comment:2 Changed 7 years ago by sindresorhus

Duplicate of #9960.

comment:3 Changed 7 years 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));

};

comment:4 Changed 7 years ago by anonymous

sorry jQuery.fn.appendChildNS = function(ns, nodeName) { var dom = document.implementation.createDocument(ns, nodeName, null); var element=dom.createElement(nodeName); this.append(element);

};

Note: See TracTickets for help on using tickets.