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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With