Created
March 1, 2012 09:47
-
-
Save tikitikipoo/1948607 to your computer and use it in GitHub Desktop.
エレガントなやり方で任意の要素の中身を削除する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 出所 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