jquery append() method on empty XML element

Posted by Anthony on Stack Overflow See other posts from Stack Overflow or by Anthony
Published on 2010-05-26T04:33:12Z Indexed on 2010/05/26 4:41 UTC
Read the original article Hit count: 215

Filed under:
|
|

This could just be a syntax error, but I'm trying to create a Document object from scratch, starting with document.implementation.createDocument() and then using jquery's append() method to add the elements. But it's not appending:

var myDoc = document.implementation.createDocument("", 'stuff', null);

$("stuff",myDoc).attr("test","tested");

$("stuff",myDoc).append("<test>A</test>");
$("<test>B</test>").appendTo("stuff",soapEnv);

var s = new XMLSerializer();
alert(s.serializeToString(soapEnv));

This should output:

<stuff test="tested">
    <test>A</test>
    <test>B</test>
</stuff>

But instead it outputs:

<stuff test="tested" />

So the selector seems to be working, just not the method. My only guess is the method doesn't account for the fact that elements are empty (<stuff />) until they have children. But that's just a guess.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about Xml