Proprietà Anchor href
Esempio
Modifica la destinazione (URL) di un collegamento:
document.getElementById("myAnchor").href = "http://www.cnn.com/";
Definizione e utilizzo
La proprietà href imposta o restituisce il valore dell'attributo href di un collegamento.
L'attributo href specifica la destinazione di un collegamento.
Supporto del browser
Property | |||||
---|---|---|---|---|---|
href | Yes | Yes | Yes | Yes | Yes |
Sintassi
Restituisci la proprietà href:
anchorObject.href
Imposta la proprietà href:
anchorObject.href = URL
Valori di proprietà
Value | Description |
---|---|
URL |
Specifies the URL of the link. Possible values:
|
Dettagli tecnici
Valore di ritorno: | Una stringa, che rappresenta l'URL del collegamento. Restituisce l'intero URL, incluso il protocollo (come http://) |
---|
Altri esempi
Esempio
Ottieni l'URL di un collegamento:
var x = document.getElementById("myAnchor").href;
Esempio
Un altro esempio di come ottenere l'URL di un collegamento (un URL relativo):
var x =
document.getElementById("myAnchor").href;
Pagine correlate
Riferimento HTML: attributo HTML <a> href
❮ Ancora oggetto