Attributo href Anchor
Definizione e uso
href
L'attributo imposta o restituisce il collegamento Valore dell'attributo href.
href
L'attributo definisce il destinatario del collegamento.
Esempio
Esempio 1
Cambia il destinatario del collegamento (URL):
document.getElementById("myAnchor").href = "https://www.codew3c.com/";
Esempio 2
Ottieni l'URL del collegamento:
var x = document.getElementById("myAnchor").href;
Esempio 3
Un altro esempio su come ottenere l'URL del collegamento (URL relativo):
var x = document.getElementById("myAnchor").href;
Sintassi
Restituisce l'attributo href:
anchorObject.href
Imposta l'attributo href:
anchorObject.href = URL
Valore dell'attributo
Valore | Descrizione |
---|---|
URL |
Determina l'URL del collegamento. Valori possibili:
|
Dettagli tecnici
Valore di ritorno: | Valore di stringa, che rappresenta l'URL del link. Restituisce l'intero URL, inclusi il protocollo (ad esempio http://). |
---|
Supporto dei browser
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Supporto | Supporto | Supporto | Supporto | Supporto |
Pagine correlate
Manuale di riferimento HTML:Valore dell'attributo href del tag <a> HTML