Home >Web Front-end >H5 Tutorial >HTML5 Tips: Obtain the head element through document.head_html5 Tutorial Tips

HTML5 Tips: Obtain the head element through document.head_html5 Tutorial Tips

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 15:47:452543browse

Today, I looked at a foreign website and found that the head element is obtained as follows


Copy code
The code is as follows:

var head = document.head || document .getElementsByTagName('head')[0];

The latter is our commonly used method, and the previous document.head is actually the first time we see it. After checking the information, I found that it turned out to be HTML5 stuff. It's really simple, just one attribute.

Of course, IE6/7/8 does not support it. IE9/Safari/Chrome/FF/Opera are all supported (latest version). Record it.

The HTMLDocument interface in html4 is as follows

The HTMLDocument interface in html5 is as follows

Related:

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268

http://www.w3.org/TR/html5/dom.html#html-documents

http://msdn.microsoft.com/en-us/library/gg593004(v=VS.85)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn