Link href-eigenschap

Definitie en gebruik

href Instellen of teruggeven van de URL van het gelinkte document.

Zie ook:

HTML Referentiemanual:HTML <link> href attribute

HTML Referentiemanual:HTML <link> tag

Voorbeeld

Voorbeeld 1

Geef de URL van het gelinkte document terug:

var x = document.getElementById("myLink").href;

Probeer het zelf

Voorbeeld 2

Wijzig de stylesheet:

document.getElementById("myLink").href = "style2.css";

Probeer het zelf

Syntax

Geef de href-eigenschap terug:

linkObject.href

Stel de href-eigenschap in:

linkObject.href = URL

Eigenschapswaarde

Waarde Beschrijving
URL

Stelt de URL van het gelinkte resource/document vast.

Mogelijke waarden:

  • Absoluut URL - verwijst naar een andere website (bijvoorbeeld href="http://www.example.com/default.html")
  • Relative URL - refers to files within the website (such as href="default.html"))

Technical details

Return value: A string value that represents the URL of the linked document. Returns the entire URL, including the protocol (such as http://).

Browser support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support