2

Is it too lame to write like this?

var html = $('html');

Seems that html is equal to $(window) or $(document)?

How can it be replaced by a crossbrowser native javascript?

Mark
  • 235
  • 3
  • 9

1 Answers1

7

The top-level element (html in the case of HTML documents) is available as document.documentElement (references: spec | MDN).

And of course, if you want to use jQuery stuff on it, get a jQuery wrapper: $(document.documentElement).

In terms of cross-browser support, I'd be fairly shocked if you found anything even vaguely recent that didn't support it (and that includes IE6), it was actually in DOM1, which was a long time ago. See this related question on that very topic.

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Seems it should be $(document.documentElement) for the object usage. – Mark Dec 14 '12 at 11:16
  • @Steve: Yes, very well supported, it was actually in DOM1, which was a **long** time ago (not that that necessarily means anything). Yes, you'd wrap it in a jQuery instance if you want a jQuery wrapper; you said "native JavaScript" so I didn't include the jQuery wrapper. – T.J. Crowder Dec 14 '12 at 11:18