The hash
property sets or gets the anchor part of a URL, including the hash sign (#).
hash |
Yes | Yes | Yes | Yes | Yes |
Return the hash property.
var v = location.hash
Set the hash property.
location.hash=anchorname
Value | Type | Description |
---|---|---|
anchorname | String | Set the anchor part of a URL |
A String type value representing the anchor part of the URL, including the hash sign (#).
The following code shows how to Set the anchor part.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!-- w ww.java 2 s .c o m-->
<script>
function myFunction() {
location.hash = "part";
var x = location.hash;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: