欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

html5小技巧之通过document.head获取head元素

程序员文章站 2023-12-04 11:16:10
html5中通过document.head获取head元素... 14-06-04...

今天,看一个国外网站发现人家获取head元素如下


复制代码
代码如下:

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

后面的是我们常用的方式,前面的 document.head 着实第一次见。查资料发现原来是html5的东东。的确简单了,一个属性搞定。

当然,ie6/7/8不支持。ie9/safari/chrome/ff/opera均支持(最新版本)。记录下。

html4中htmldocument接口如下

html5小技巧之通过document.head获取head元素

html5中htmldocument接口如下

html5小技巧之通过document.head获取head元素

相关:

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%28v=vs.85%29