Atribut href Anchor
Definisi dan penggunaan
href
Atur atau kembalikan tautan Nilai atribut href.
href
Atribut menentukan tujuan tautan.
Contoh
Contoh 1
Ubah tujuan tautan (URL):
document.getElementById("myAnchor").href = "https://www.codew3c.com/";
Contoh 2
Ambil URL tautan:
var x = document.getElementById("myAnchor").href;
Contoh 3
Contoh lainnya bagaimana mengambil URL tautan (URL relatif):
var x = document.getElementById("myAnchor").href;
Sintaks
Kembalikan atribut href:
anchorObject.href
Atur atribut href:
anchorObject.href = URL
Nilai atribut
Nilai | Deskripsi |
---|---|
URL |
Tentukan URL tautan. Nilai yang mungkin:
|
Detil Teknis
Nilai pengembalian: | Nilai string, menunjukkan URL tautan. Mengembalikan URL penuh, termasuk protokol (seperti http://). |
---|
Dukungan Peramban
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Dukungan | Dukungan | Dukungan | Dukungan | Dukungan |
Halaman yang berhubungan
Panduan Referensi HTML:Nilai atribut href Tag <a> HTML