Modify ↓
Ticket #12154 (closed bug: invalid)
.replaceWith() seems to erase document when used on root.
| Reported by: | gravitezero@… | Owned by: | gravitezero@… |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.7.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
It seems that when I use .replaceWith() on the root element of the DOM, it erase the document.
My document :
<content><p>stuffs</p></content>
The code :
var content = $(doc).find('content');
content.replaceWith(content.html());
Instead I use :
var content = $(doc).find('content');
content.after(content.html());
content.remove();
Change History
comment:2 Changed 10 months ago by dmethvin
- Owner set to gravitezero@…
- Status changed from new to pending
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 10 months ago by gravitezero@…
- Status changed from pending to new
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
$doc.find(key).html(meta[key]);
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

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