Created
February 24, 2012 01:52
-
-
Save ethertank/1896639 to your computer and use it in GitHub Desktop.
HTMLElement.insertBefore のラッパー関数
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
挿入先要素の親要素の指定を自動化。 | |
### usage ### | |
[html] | |
<div><div id="target">target</div></div> | |
[js] | |
var doc = document, elm = doc.createElement("div"), targetElm = doc.getElementById("target"); | |
elm.appendChild(doc.createTextNode("insert !")); | |
insertBefore(elm, targetElm); |
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
function insertBefore(newElm,targetElm) { | |
targetElm.parentNode.insertBefore(newElm, targetElm); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment