Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: how to add XML node?

Tags:

jquery

xml

Assume parentNode exists and I want to add an element "Child" to it. Following intutive code won't work:

$("<Child>").appendTo(parentNode);

Because jQuery will create a node and append to parentNode.

So I am wondering, how do you add xml child node in jQuery?

p.s. Following ugly code will work, but it is really really ugly:

parentNode.appendChild(parentNode.ownerDocument.createElement("Child"));

p.s.2 $(parentNode).append('<Child >) won't append the child node with jQuery 1.2.6 on FireFox 3. Actually it append nothing. If use appendTo(), it will append a node with name CHILD (all capital).


1 Answers

JQuery is not meant to treat xml. When you use $("<Child/>") JQuery uses a hidden div innerHTML to build the child node, that's why the capitalization differs.

like image 58
Serxipc Avatar answered Mar 23 '26 10:03

Serxipc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!