Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better insert before document.documentElement.firstChild #71

Open
mathiasbynens opened this issue Mar 25, 2011 · 1 comment
Open

Better insert before document.documentElement.firstChild #71

mathiasbynens opened this issue Mar 25, 2011 · 1 comment
Labels

Comments

@mathiasbynens
Copy link
Contributor

This kinda technique is used throughout has.js:

root = d.body || (function(){
    fake = true;
    return de.insertBefore(d.createElement("body"), de.firstChild);
}());

E.g. https://github.com/phiggins42/has.js/blob/master/detect/bugs.js#L102-105

Might be worthwhile to use de.firstElementChild || de.firstChild instead, in case the firstChild is a comment node and the browser doesn’t support inserting before comment nodes.

(Props to Paul Irish for pointing out the mistake in my <details>/<summary> feature test, and John-David Dalton for coming up with this elegant solution.)

@jdalton
Copy link
Contributor

jdalton commented Apr 6, 2011

Imma try to apply this tonight :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants