aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/api/childnode/remove/index.html
blob: bae33f75c0304f35df87b77e4de2df28de357321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
title: ChildNode.remove()
slug: Web/API/ChildNode/remove
tags:
  - API
  - ChildNode
  - DOM
  - Experimentell
  - Méthode
translation_of: Web/API/ChildNode/remove
---
<div>{{APIRef("DOM")}}</div>

<p>Die <code><strong>ChildNode.remove()</strong></code> Methode entfernt ein Objekt aus der Baumstruktur ("tree") zu der es gehört.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox"><em>node</em>.remove();
</pre>

<h2 id="Beispiel">Beispiel</h2>

<h3 id="Benutzung_von_remove()">Benutzung von <code>remove()</code></h3>

<pre class="brush: html">&lt;div id="div-01"&gt;Dies ist div-01&lt;/div&gt;
&lt;div id="div-02"&gt;Dies ist div-02&lt;/div&gt;
&lt;div id="div-03"&gt;Dies ist div-03&lt;/div&gt;
</pre>

<pre class="brush: js">var el = document.getElementById('div-02');
el.remove(); // Entfernt das div Element mit der id 'div-02'
</pre>

<h3 id="ChildNode.remove()_kann_nicht_gescopet_werden"><code>ChildNode.remove()</code> kann nicht gescopet werden</h3>

<p>Die <code>remove()</code> Methode kann nicht mit dem <code>with</code> Statement gescopet werden. {{jsxref("Symbol.unscopables")}} enthält mehr Informationen darüber.</p>

<pre class="brush: js">with(node) {
  remove();
}
// Erzeught einen ReferenceError</pre>

<h2 id="Polyfill">Polyfill</h2>

<p>Ein Polyfill der <code>remove()</code> Methode in Internet Explorer 9 und höher sieht folgendermaßen aus:</p>

<pre class="brush: js">// von:https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/remove()/remove().md
(function (arr) {
  arr.forEach(function (item) {
    if (item.hasOwnProperty('remove')) {
      return;
    }
    Object.defineProperty(item, 'remove', {
      configurable: true,
      enumerable: true,
      writable: true,
      value: function remove() {
        if (this.parentNode !== null)
          this.parentNode.removeChild(this);
      }
    });
  });
})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);</pre>

<h2 id="Specifikationen">Specifikationen</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specifikation</th>
   <th scope="col">Status</th>
   <th scope="col">Kommentar</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM WHATWG', '#dom-childnode-remove', 'ChildNode.remove')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td>Erste Definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>


<p>{{Compat("api.ChildNode.remove")}}</p>
</div>

<h2 id="Siehe_auch">Siehe auch</h2>

<ul>
 <li>Das reine {{domxref("ChildNode")}} Interface.</li>
 <li>
  <div class="syntaxbox">Objekttypen die dieses Interface implementieren: {{domxref("CharacterData")}}, {{domxref("Element")}} und {{domxref("DocumentType")}}.</div>
 </li>
</ul>