Anchor hrefAttribute

Anchor 对象参考手册Anchor Object

Definition and Usage

The href attribute sets or returns the value of the href attribute in a link.

The href attribute specifies the URL of the linked resource.

Syntax

Set the href attribute:

anchorObject.href="URL.html"

Return the href attribute:

anchorObject.href

Value Description
URL The URL of the linked resource


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the href attribute


Example

Example

Return the value of the href attribute in the link:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Example (example.com)</title> </head> <body> <p><a id="example" href="//www.example.com/">Example</a></p> <script>document.write("Return href link: "); document.write(document.getElementById('example').href);</script> </body> </html>

Try it Yourself »


Anchor 对象参考手册Anchor Object Other Extensions