Skip to main content

Bug Tracker

Side navigation

#12154 closed bug (invalid)

Opened July 27, 2012 12:14PM UTC

Closed July 27, 2012 01:04PM UTC

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

Reported by: Owned by:
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');
Attachments (0)
Change History (4)

Changed July 27, 2012 12:24PM UTC by anonymous comment:1

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

Changed July 27, 2012 12:32PM UTC by dmethvin comment:2

owner: →
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?

Changed July 27, 2012 12:58PM UTC by comment:3

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

Changed July 27, 2012 01:04PM UTC by dmethvin comment:4

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.