Skip to content

Instantly share code, notes, and snippets.

@miya2000
Created March 4, 2010 21:38
Show Gist options
  • Select an option

  • Save miya2000/322145 to your computer and use it in GitHub Desktop.

Select an option

Save miya2000/322145 to your computer and use it in GitHub Desktop.
(function(){
var df1 = document.createDocumentFragment();
df1.appendChild(document.createElement('A'));
var df2 = document.createDocumentFragment();
df2.appendChild(df1);
alert(df1.firstChild && df1.firstChild.nodeName); // null
alert(df2.firstChild && df2.firstChild.nodeName); // A
var range = document.createRange();
range.setStartBefore(df2.firstChild);
range.setEndAfter(df2.lastChild);
var df3 = range.extractContents();
alert(df2.firstChild && df2.firstChild.nodeName); // null
alert(df3.firstChild && df3.firstChild.nodeName); // A
document.body.appendChild(df3);
alert(df3.firstChild && df3.firstChild.nodeName); // null
})()
http://d.hatena.ne.jp/miya2000/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment