<Elemen Object Show ContohLepaskan pertama <li> elemen dari daftar: var list = document.getElementById("myList"); // Get the <ul> element with id="myList" Sebelum menghapus:
Setelah menghapus:
Cobalah sendiri " Lebih "Try it Yourself" contoh di bawah ini. Definisi dan PenggunaanThe removeChild() metode menghapus node anak tertentu dari elemen tertentu. Mengembalikan simpul yang dihapus sebagai objek Node, atau null jika node tidak ada. Catatan: node anak yang dihapus tidak lagi bagian dari DOM. Namun, dengan referensi dikembalikan oleh metode ini, adalah mungkin untuk memasukkan anak dipindahkan ke elemen di lain waktu (See "More Examples") . Tip: Gunakan appendChild() atau insertBefore() metode untuk memasukkan node yang dihapus ke dalam dokumen yang sama. Untuk masukkan ke dokumen lain, menggunakan dokumen. adoptNode() atau dokumen. importNode() metode. Dukungan Browser
SintaksisNilai parameter
Rincian teknis
Contoh lebihContohCari tahu apakah daftar memiliki setiap node anak. Jika demikian, menghapus node anak pertama (index 0) : // Get the <ul> element with id="myList" // If the <ul> element has any child nodes, remove its first child node Sebelum menghapus:
Sebelum menghapus:
Cobalah sendiri " ContohHapus semua node anak dari daftar: // Get the <ul>
element with id="myList" // As long as <ul> has a child node, remove it Sebelum menghapus:
Setelah menghapus: Cobalah sendiri " ContohMenghapus <li> elemen dengan id = "myLI" dari elemen induknya (tanpa menentukan simpul induknya): var item = document.getElementById("myLI"); Sebelum menghapus:
Setelah menghapus:
Cobalah sendiri " ContohMenghapus <li> elemen dari induknya, dan masukkan lagi: var item = document.getElementById("myLI"); function removeLi() { function appendLi() { Cobalah sendiri " ContohMenghapus <span> elemen dari induknya dan masukkan ke <h2> elemen dalam dokumen lain: var child = document.getElementById("mySpan"); function removeLi() { function
myFunction() { Cobalah sendiri " <Elemen Object (PHP 5, PHP 7, PHP 8) DOMNode::removeChild — Removes child from list of children Descriptionpublic DOMNode::removeChild(DOMNode Parameterschild The removed child. Return ValuesIf the child could be removed the function returns the old child. Errors/ExceptionsDOM_NO_MODIFICATION_ALLOWED_ERR Raised if this node is readonly. DOM_NOT_FOUND Raised if Examples The following example will delete the Example #1 Removing a child
= new DOMDocument; The above example will output: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> <book id="listing"> <title>My lists</title> </book> See Also
crazy888s at hotmail dot com ¶ 13 years ago
vsematika at centrum dot cz ¶ 17 years ago
Justin Sheckler ¶ 13 years ago
deleteChildren($node) {
Justin Carlson ¶ 12 years ago
Kenney ¶ 9 years ago
Michael D (DigitalGemstones.com) ¶ 14 years ago
nggit@phpindonesia ¶ 3 years ago
Wala ¶ 14 years ago
blaine (at) blainegarrett (dot com) ¶ 17 years ago
drimsun at gmail dot com ¶ 12 years ago
tim cameron ryan ¶ 14 years ago
pedro at leb dot usp dot br ¶ 17 years ago
Vasil Rangelov ¶ 14 years ago
mytto at openxtrem dot com ¶ 17 years ago
|