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: | gravitezero@gmail.com | Owned by: | gravitezero@gmail.com |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
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();
Attachments (0)
Change History (4)
Changed July 27, 2012 12:24PM UTC by comment:1
Changed July 27, 2012 12:32PM UTC by comment:2
owner: | → gravitezero@gmail.com |
---|---|
status: | new → 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?
Changed July 27, 2012 12:58PM UTC by comment:3
status: | pending → 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]);
Changed July 27, 2012 01:04PM UTC by comment:4
resolution: | → invalid |
---|---|
status: | new → closed |
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.
I can't past this code into jsFiddle, because it automatically adds a
body
tag, so the situation is different.