HTML DOM Document head attribute
- Previous Page hasFocus()
- Next Page Images
- Go Up One Level HTML DOM Documents
Definition and usage
head
This property returns the document's <head> element.
Tip
If there is no <head> element, HTML will add an empty element.
If there are multiple <head> elements, this property returns the first one.
See also:
Instance
Example 1
Get the tag name of the <head> element:
document.head.tagName;
Example 2
Try using a document without a <head> element:
document.head.tagName;
Example 3
Get the tag name of the first child element of the <head> element:
document.head.firstElementChildtagName;
Example 4
You can also use getElementsByTagName("head") to access the <head> element:
getElementsByTagName("head")[0].tagName;
Syntax
document.head
Return value
Type | Description |
---|---|
Node | The document's head element. |
Browser support
document.head
It is a feature of DOM Level 3 (2004).
All browsers support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous Page hasFocus()
- Next Page Images
- Go Up One Level HTML DOM Documents