Bug Tracker

Modify

Ticket #12154 (closed bug: invalid)

Opened 10 months ago

Last modified 10 months ago

.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:1 Changed 10 months 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 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]);

comment:4 Changed 10 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.