Skip to content

Instantly share code, notes, and snippets.

@tikitikipoo
Created March 1, 2012 09:47
Show Gist options
  • Save tikitikipoo/1948607 to your computer and use it in GitHub Desktop.
Save tikitikipoo/1948607 to your computer and use it in GitHub Desktop.
エレガントなやり方で任意の要素の中身を削除する
// 出所 http://members.jcom.home.ne.jp/jintrick/Personal/DOM_Range.html#EMPT_DIV
// http://moz-addon.g.hatena.ne.jp/ZIGOROu/20080917/1221636061
// jQueryのやり方
// http://james.padolsey.com/jquery/#v=1.6.2&fn=jQuery.fn.empty
while(div.lastChild){
div.removeChild(div.lastChild);
}
// エレガントなやり方
var range = document.createRange();
range.selectNodeContents(div);
range.deleteContents();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment