English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
hashAttribute sets or returns the anchor part of the URL, including the hash mark (#).
If the URL does not have a fragment identifier, this attribute returns an empty string "".
Note:When using this attribute to set the anchor part, do not include the hash mark (#).
Return hash attribute:
location.hash
Set hash attribute:
location.hash = anchorName
var anchor = document.getElementById("myAnchor"); document.querySelector("#output").innerHTML = anchor.hash;Test and See‹/›
All browsers fully support the hash attribute:
Attribute | |||||
hash | Yes | Yes | Yes | Yes | Yes |
Value | Description |
---|---|
anchorName | A string specifying the anchor part of the URL |
Return Value: | A string representing the anchor part of the URL, including the hash (#) |
---|
Set Anchor Part:
var anchor = document.getElementById("myAnchor"); anchor.hash = "newFragement";Test and See‹/›
Location Reference:location.href property
Location Reference:location.hostname property
Location Reference:location.pathname property
Location Reference:location.protocol property