Properti HTML DOM nodeValue
Contoh
Dapatkan nilai simpul dari elemen <button> pertama dalam dokumen:
var x = document.getElementsByTagName("BUTTON")[0].childNodes[0].nodeValue;
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Properti nodeValue menetapkan atau mengembalikan nilai node dari node yang ditentukan.
Jika node adalah node elemen, properti nodeValue akan mengembalikan null.
Catatan: Jika Anda ingin mengembalikan teks suatu elemen, ingatlah bahwa teks selalu berada di dalam simpul Teks , dan Anda harus mengembalikan nilai simpul simpul Teks ( elemen .childNodes[0].nodeValue).
Untuk tipe node lainnya, properti nodeValue akan mengembalikan nilai yang berbeda untuk tipe node yang berbeda.
Tip: Alternatif untuk properti nodeValue dapat berupa properti textContent .
Dukungan Peramban
Property | |||||
---|---|---|---|---|---|
nodeValue | Yes | Yes | Yes | Yes | Yes |
Sintaksis
Kembalikan nilai simpul:
node.nodeValue
Tetapkan nilai simpul:
node.nodeValue = value
Nilai properti
Value | Description |
---|---|
value | Specifies the node value of the specified node |
Detail Teknis
Nilai Kembali: | Sebuah String, mewakili nilai dari node.
Nilai yang mungkin:
|
---|---|
Versi DOM | Objek Node Tingkat 1 Inti |
Lebih Banyak Contoh
Contoh
Dapatkan nama simpul, nilai simpul, dan jenis simpul dari simpul anak pertama elemen <div>:
<div id="myDIV">This is a div element.</div>
<script>
var x = document.getElementById("myDIV").firstChild;
var txt = "";
txt += "The node name: " + x.nodeName + "<br>";
txt += "The node value: " + x.nodeValue + "<br>";
txt += "The node type: " + x.nodeType;
</script>
Halaman Terkait
Referensi DOM HTML: simpul. properti nodeName
Referensi DOM HTML: simpul. properti nodeType
Referensi DOM HTML: simpul. properti nodeValue
Referensi DOM HTML: simpul. properti childNodes