Reputation:
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).
Upvotes: 3
Views: 7355
Reputation: 6699
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.
Upvotes: 2