<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DOM Traversal Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/dom-traversal/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/dom-traversal/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Wed, 13 Apr 2022 16:30:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>How To Traverse The DOM In JavaScript?</title>
		<link>https://www.scmgalaxy.com/tutorials/how-to-traverse-the-dom-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/how-to-traverse-the-dom-in-javascript/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Sat, 07 Aug 2021 09:22:38 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[DOM Traversal]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Node]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7538</guid>

					<description><![CDATA[<p>DOM Traversal parentNode – Returns parent node parentElement – Returns parent element node childNodes – Returns collection of an element’s [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-to-traverse-the-dom-in-javascript/">How To Traverse The DOM In JavaScript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading"><strong>DOM Traversal</strong></h2>



<ul class="wp-block-list"><li><strong>parentNode – Returns parent node</strong></li><li><strong>parentElement – Returns parent element node</strong></li><li><strong>childNodes – Returns collection of an element’s child nodes (including text and comment nodes)</strong></li><li><strong>children – Returns a collection of an element’s child element node (do not include text and comment nodes)</strong></li><li><strong>firstChild – Returns first child node of an element (it can be text or comment node)</strong></li><li><strong>firstElementChild – Returns first child element node of an element</strong></li><li><strong>lastChild &#8211; Returns last child node of an element (it can be text or comment node)</strong></li><li><strong>lastElementChild – Returns last child element node of an element</strong></li><li><strong>previousSibling &#8211; Returns previous node of the same level (it can be text or comment node)</strong></li><li><strong>previousElementSibling – Returns previous element node of the same level</strong></li><li><strong>nextSibling &#8211; Returns next node of same level (it can be text or comment node)</strong></li><li><strong>nextElementSibling – Returns next element of same level</strong></li></ul>



<h2 class="wp-block-heading"><strong>parentNode and parentElement</strong></h2>



<p class="wp-block-paragraph">The parentNode read-only property returns the parent of the specified node in the DOM tree.</p>



<p class="wp-block-paragraph">The parentElement property returns the parent element of the specified element. If the parent node is not an element node, it returns null.</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="631" height="296" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-document-2.png" alt="" class="wp-image-7552" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-document-2.png 631w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-document-2-300x141.png 300w" sizes="(max-width: 631px) 100vw, 631px" /></figure>



<h2 class="wp-block-heading"><strong>childNodes</strong></h2>



<p class="wp-block-paragraph">The childNode<strong>s</strong> read-only property returns a live NodeList of child nodes of the given element where the first child node is assigned index 0. childNodes includes all child nodes, including non-element nodes like text and comment nodes.</p>



<ul class="wp-block-list"><li>Whitespace inside elements is considered as text, and text is considered as nodes.</li><li>Any whitespace will create a #text node, from a single space to multiple spaces, returns, tabs, and so on.</li><li>You can use the length property of the NodeList object to determine the number of child nodes, then you can loop through all child nodes and extract the other info.</li></ul>



<h2 class="wp-block-heading"><strong>children</strong></h2>



<p class="wp-block-paragraph">The children property returns collection of child elements of the given element where the first child is assigned index 0. children include only element nodes (no whitespace, text node, and comment node).</p>



<ul class="wp-block-list"><li>You can use the length property of the NodeList object to determine the number of child nodes, then you can loop through all child nodes and extract the other info.</li></ul>



<h2 class="wp-block-heading"><strong>firstChild</strong></h2>



<p class="wp-block-paragraph">The firstChild property returns the node&#8217;s first child in the tree, or null if the node has no children. If the node is a Document, it returns the first node in the list of its direct children. It includes a text node and a comment node.</p>



<ul class="wp-block-list"><li>Whitespace inside elements is considered as text, and text is considered as nodes.</li><li>Any whitespace will create a #text node, from a single space to multiple spaces, returns, tabs, and so on.</li></ul>



<h2 class="wp-block-heading"><strong>firstElementChild</strong></h2>



<p class="wp-block-paragraph">The firstElementChild property returns the element&#8217;s first child element node in the tree, or null if the node has no children element. It ignores text node and comment node or any whitespaces.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="631" height="296" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-document-1.png" alt="" class="wp-image-7550" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-document-1.png 631w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-document-1-300x141.png 300w" sizes="(max-width: 631px) 100vw, 631px" /></figure>



<h2 class="wp-block-heading"><strong>lastChild</strong></h2>



<p class="wp-block-paragraph">The lastChild read-only property returns the last child of the node. If its parent is an element, then the child is generally an element node, a text node, or a comment node. It returns null if there are no child elements.</p>



<ul class="wp-block-list"><li>Whitespace inside elements is considered as text, and text is considered as nodes.</li><li>Any whitespace will create a #text node, from a single space to multiple spaces, returns, tabs, and so on.</li></ul>



<h2 class="wp-block-heading"><strong>lastElementChild</strong></h2>



<p class="wp-block-paragraph">The lastElementChild property returns the element&#8217;s last child element node in the tree, or null if the node has no children element. It ignores text node and comment node or any whitespaces.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="631" height="296" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-document.png" alt="" class="wp-image-7547" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-document.png 631w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-document-300x141.png 300w" sizes="(max-width: 631px) 100vw, 631px" /></figure>



<h2 class="wp-block-heading"><strong>previousSibling</strong></h2>



<p class="wp-block-paragraph">The previousSibling read-only property returns the node immediately preceding the specified one in its parent&#8217;s childNodes list, or null if the specified node is the first in that list. It includes text node and comment node or any whitespace.</p>



<h2 class="wp-block-heading"><strong>previousElementSibling</strong></h2>



<p class="wp-block-paragraph">The previousElementSibling property returns the element node immediately preceding the specified one in its parent&#8217;s node list, or null if the specified node is the first in that list. It ignores the text node and comment node or any whitespace.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="635" height="292" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-2.png" alt="" class="wp-image-7545" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-2.png 635w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-2-300x138.png 300w" sizes="auto, (max-width: 635px) 100vw, 635px" /></figure>



<h2 class="wp-block-heading"><strong>nextSibling</strong></h2>



<p class="wp-block-paragraph">The nextSibling read-only property returns the node immediately following the specified one in its parent&#8217;s childNodes list, or null if the specified node is the last node in that list. It includes text node and comment node or any whitespace.</p>



<h2 class="wp-block-heading"><strong>nextElementSibling</strong></h2>



<p class="wp-block-paragraph">The nextElementSibling read-only property returns the element node immediately following the specified one in its parent&#8217;s node list, or null if the specified node is the last node in that list. It ignores the text node and comment node or any whitespace.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="639" height="307" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node.png" alt="" class="wp-image-7544" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node.png 639w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/element-node-300x144.png 300w" sizes="auto, (max-width: 639px) 100vw, 639px" /></figure>



<h2 class="wp-block-heading"><strong>ownerDocument</strong></h2>



<p class="wp-block-paragraph">The ownerDocument read-only property returns the top-level document object for this node. In HTML, the HTML document itself is always the ownerDocument of an element.</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-to-traverse-the-dom-in-javascript/">How To Traverse The DOM In JavaScript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/how-to-traverse-the-dom-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
