aboutsummaryrefslogtreecommitdiff
path: root/files/pl/web/api/parentnode/index.html
blob: 2cbf79f11c89f93e9cd109d1a4a5e18ad4126886 (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
---
title: ParentNode
slug: Web/API/ParentNode
tags:
  - API
  - DOM
  - Finding Elements
  - Finding Nodes
  - Interface
  - Locating Elements
  - Locating Nodes
  - Managing Elements
  - Managing Nodes
  - Mixin
  - NeedsTranslation
  - Node
  - ParentNode
  - Reference
  - Selectors
  - TopicStub
translation_of: Web/API/ParentNode
---
<div>{{APIRef("DOM")}}</div>

<p><span class="seoSummary">The <code><strong>ParentNode</strong></code> mixin contains methods and properties that are common to all types of {{domxref("Node")}} objects that can have children.</span> It's implemented by {{domxref("Element")}}, {{domxref("Document")}}, and {{domxref("DocumentFragment")}} objects.</p>

<p>See <a href="/en-US/docs/Web/API/Document_object_model/Locating_DOM_elements_using_selectors">Locating DOM elements using selectors</a> to learn how to use <a href="/en-US/docs/Web/CSS/CSS_Selectors">CSS selectors</a> to find nodes or elements of interest.</p>

<h2 id="Properties">Properties</h2>

<dl>
	<dt>{{domxref("ParentNode.childElementCount")}} {{readonlyInline}}</dt>
	<dd>Returns the number of children of this <code>ParentNode</code> which are elements.</dd>
	<dt>{{domxref("ParentNode.children")}} {{readonlyInline}}</dt>
	<dd>Returns a live {{domxref("HTMLCollection")}} containing all of the {{domxref("Element")}} objects that are children of this <code>ParentNode</code>, omitting all of its non-element nodes.</dd>
	<dt>{{domxref("ParentNode.firstElementChild")}} {{readonlyInline}}</dt>
	<dd>Returns the first node which is both a child of this <code>ParentNode</code> <em>and</em> is also an <code>Element</code>, or <code>null</code> if there is none.</dd>
	<dt>{{domxref("ParentNode.lastElementChild")}} {{readonlyInline}}</dt>
	<dd>Returns the last node which is both a child of this <code>ParentNode</code> <em>and</em> is an <code>Element</code>, or <code>null</code> if there is none.</dd>
</dl>

<h2 id="Methods">Methods</h2>

<dl>
	<dt>{{domxref("ParentNode.append()")}} {{experimental_inline}}</dt>
	<dd>Inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects after the last child of the <code>ParentNode</code>. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.</dd>
	<dt>{{domxref("ParentNode.prepend()")}} {{experimental_inline}}</dt>
	<dd>Inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects before the first child of the <code>ParentNode</code>. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.</dd>
	<dt>{{domxref("ParentNode.querySelector()")}}</dt>
	<dd>Returns the first {{domxref("Element")}} with the current element as root that matches the specified group of selectors.</dd>
	<dt>{{domxref("ParentNode.querySelectorAll()")}}</dt>
	<dd>Returns a {{domxref("NodeList")}} representing a list of elements with the current element as root that matches the specified group of selectors.</dd>
</dl>

<h2 id="Specification">Specification</h2>

<table class="standard-table">
	<tbody>
		<tr>
			<th scope="col">Specification</th>
			<th scope="col">Status</th>
			<th scope="col">Comment</th>
		</tr>
		<tr>
			<td>{{SpecName('DOM WHATWG', '#parentnode', 'ParentNode')}}</td>
			<td>{{Spec2('DOM WHATWG')}}</td>
			<td>Split the <code>ElementTraversal</code> interface into {{domxref("ChildNode")}} and {{domxref("ParentNode")}}. The {{domxref("ParentNode.firstElementChild")}}, {{domxref("ParentNode.lastElementChild")}}, and {{domxref("ParentNode.childElementCount")}} properties are now defined on the latter. Added the {{domxref("ParentNode.children")}} property, and the {{domxref("ParentNode.querySelector()")}}, {{domxref("ParentNode.querySelectorAll()")}}, {{domxref("ParentNode.append()")}}, and {{domxref("ParentNode.prepend()")}} methods.</td>
		</tr>
		<tr>
			<td>{{SpecName('Element Traversal', '#interface-elementTraversal', 'ElementTraversal')}}</td>
			<td>{{Spec2('Element Traversal')}}</td>
			<td>Added the initial definition of its properties to the <code>ElementTraversal</code> pure interface and used it on {{domxref("Element")}}.</td>
		</tr>
	</tbody>
</table>

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



<p>{{Compat("api.ParentNode")}}</p>

<h2 id="See_also">See also</h2>

<ul>
	<li>The {{domxref("ChildNode")}} pure interface.</li>
	<li>
	<div class="syntaxbox">Object types implementing this mixin: {{domxref("Document")}}, {{domxref("Element")}}, and {{domxref("DocumentFragment")}}.</div>
	</li>
</ul>