jQuery DOM append losing markup

Posted by Raj on Stack Overflow See other posts from Stack Overflow or by Raj
Published on 2010-09-09T18:38:56Z Indexed on 2010/12/24 2:54 UTC
Read the original article Hit count: 227

Filed under:
|
|

This is related to an earlier question. I try to append HTML DOM returned in an AJAX response to an existing DIV. I see all the text, but it seems all markup such as bold, italic, etc is lost.

My AJAX (XML) data is like so:

<event source="foo">
    <contents>
        <h1>This is an event</h1>
        This is the body of the event
    </contents>
</event>

My jQuery code does this:

$("#eventDiv").append( jData.find("contents").contents().clone() );

Attempting to do .html() on the cloned contents throws an exception: TypeError: Cannot call method 'replace' of undefined.

I am a little surprised that it is so excruciatingly hard to do this with jQuery. Am I doing something too far off the track?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery