Last active
December 10, 2015 19:48
-
-
Save DanElliottPalmer/4483297 to your computer and use it in GitHub Desktop.
Bumped into a problem with IE9 not being able to use appendChild() on the body. This little snippet helped fix it.
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
var fnAppendToBody = (function(){ | |
var domBody = document.body; | |
try { | |
var d = document.createElement('div'); | |
domBody.appendChild( d ); | |
d.parentNode.removeChild( d ); | |
} catch(e) { | |
domBody = document.documentElement.getElementsByTagName('body')[0]; | |
} | |
return function(domElm){ | |
domBody.appendChild( domElm ); | |
} | |
})(); |
Added functionality to remove the test div
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Switched it to get the body from documentElement. Safer I feel.