Bug Tracker

Opened 11 years ago

Closed 11 years ago

#12154 closed bug (invalid)

.replaceWith() seems to erase document when used on root.

Reported by: [email protected] Owned by: [email protected]
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:


It seems that when I use .replaceWith() on the root element of the DOM, it erase the document.

My document :


The code :

var content = $(doc).find('content');

Instead I use :

var content = $(doc).find('content');

Change History (4)

comment:1 Changed 11 years ago by anonymous

I can't past this code into jsFiddle, because it automatically adds a body tag, so the situation is different.

comment:2 Changed 11 years ago by dmethvin

Owner: set to [email protected]
Status: newpending

Is this an XML document? If so you'd want to use $.parseXML. If it's an HTML document, how are you getting a content element under the document element?

comment:3 Changed 11 years ago by [email protected]

Status: pendingnew

In fact, my case is a bit atypical : I use jQuery in Node to parse some DOM and insert some content. So if meta.template is <content></content>, and meta.content exist, I will replace the entire content tag with meta.content

// Creating the document
var doc  = jsdom.jsdom(meta.template? meta.template : '').createWindow().document,
    $doc = $(doc);

// Inserting content

comment:4 Changed 11 years ago by dmethvin

Resolution: invalid
Status: newclosed

Yes, it does sound very atypical and not something we can officially support since we have no unit tests for that environment. If it works, great. If it doesn't, sorry.

Note: See TracTickets for help on using tickets.