Latest web development tutorials

HTML DOM Anchor href attribute

Anchor Object Reference Anchor objects

Definition and Usage

href property sets or returns the value of the link href attribute.

href attribute specifies the URL is linked resources.

grammar

Set the href attribute:

anchorObject.href="URL"

Back href attribute:

anchorObject.href

描述
URL 被链资源的 URL


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support href attribute


Examples

Examples

Return Value link href attribute:

<html>
<body>

<p><a id="w3s" href="http://www.w3cschool.cc/">W3Schools.com</a></p>

<script>
document.write(document.getElementById("w3s").href);
</script>

</body>
</html>

Examples of the above output:

http://www.w3cschool.cc/

try it"


Anchor Object Reference Anchor objects