Contoh sederhana untuk menambah dan menghapus node HTML
| <input type = tombol onClick = appendNode () value = Tambahkan node> |
<input type = tombol onclick = removenode () value = delete node>
<Div id = result> </div>
<script>
i = 0
function appendNode () {
o = document.createElement (div);
o.innerhtml = tes i
document.geteLementById ('hasil'). AppendChild (o);
Saya
}
function removenode () {
var x = document.getElementById ('hasil');
x.removechild (x.lastchild) // hapus dari simpul terakhir
}
</script>