You are here: Reference > JavaScript > client-side > HTML DOM > properties > hash (location, a, area)

hash property (location, a, area)

Browser support:
Sets or returns the subsection (begins with a '#' sign) of the URL assigned to the object.
When you set the value of this property, do not include the '#' (hashmark) sign.

Syntax:

object.hash;
You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

String that sets or retrieves the hash subsection of the URL.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the hash property for an anchor:
<head>
    <script type="text/javascript">
        function AnalyzeTarget () {
            var anchor = document.getElementById ("myAnchor");

            var message = "";
            message += "hash: " + anchor.hash + "\n";
            message += "host: " + anchor.host + "\n";
            message += "hostname: " + anchor.hostname + "\n";
            message += "href: " + anchor.href + "\n";
            message += "pathname: " + anchor.pathname + "\n";
            message += "port: " + anchor.port + "\n";
            message += "protocol: " + anchor.protocol + "\n";
            message += "protocolLong: " + anchor.protocolLong + "\n";
            message += "search: " + anchor.search + "\n";

            alert (message);
        }
    </script>
</head>
<body>
    <a href="http://help.dottoro.com/test.php?id=2#bookmark" id="myAnchor">A sample anchor</a>
    <br /><br />
    <button onclick="AnalyzeTarget ();">Analyze the destination of the anchor above</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content