location: hash プロパティ
hash は Location インターフェイスのプロパティで、'#' に URL のフラグメント識別子が続く文字列です。これはページ上の ID で、 URL がターゲットにしようとしているものです。
フラグメントは URL デコードされません。 URL にフラグメント識別子がない場合、このプロパティは空文字列、 "" になります。
値
文字列です。
例
html
<a id="myAnchor" href="/en-US/docs/Location.href#Examples">Examples</a>
<script>
const anchor = document.getElementById("myAnchor");
console.log(anchor.hash); // '#Examples' を返す
</script>
仕様書
| Specification |
|---|
| HTML Standard # dom-location-hash-dev |
ブラウザーの互換性
BCD tables only load in the browser