Video summary
JavaScript DOM - Children, Parent & Sibling Nodes | Sigma Web Development Course - Tutorial #67
Main summary
Key takeaways
Summary
This lesson explains how to navigate the JavaScript DOM tree: inspect an element’s children, find its parent and siblings, and apply styles to selected elements.
The instructor creates a page with a .container holding five .box elements, then uses JavaScript and the browser console to demonstrate DOM properties.
Key Concepts and Methods
Nodes and Elements
- A node can be an HTML element, text, or a comment.
- Whitespace and line breaks in HTML are represented as text nodes, so they may appear when inspecting all nodes.
- An element is specifically an HTML element, such as a
div.
Inspecting Children
childNodesreturns all child nodes, including elements, text nodes, and comments.childrenreturns only child HTML elements.firstChildandlastChildreturn the first and last child nodes, which may be whitespace text nodes.firstElementChildandlastElementChildreturn the first and last child elements, excluding text and comment nodes.- Collections such as
childrenare indexed from zero. For example, index3refers to the fourth element.
Finding Parents and Siblings
parentElementmoves from an element up to its parent element.nextElementSiblingandpreviousElementSiblingfind adjacent sibling elements.nextSiblingandpreviousSiblingcan return any node, including whitespace text nodes.- Siblings share the same parent.
Changing Styles
Once an element is selected, its styles can be changed through its style property. For example, the instructor changes the last child element’s text color and background color.
Table Properties
The instructor briefly demonstrates selecting a table and accessing its rows through table.rows. Other table-related properties, such as caption and thead, are suggested for further exploration.
Practical Guidance
- Select an element, such as the page body or a container.
- Use
childNodesto access every node, orchildrento access only HTML elements. - Choose properties ending in
Elementwhen navigating among elements rather than text or comment nodes. - Use
parentElementto move upward and sibling properties to move sideways in the DOM tree. - Apply styles through the selected element’s
styleproperty. - Practise these properties in projects. An IDE’s autocomplete can help you discover available options.
- Read the course notes on “Walking the DOM” for additional clarity.
Speakers and Sources
- Speaker: CodeWithHarry, the instructor. No other speakers are featured.
- Demonstration tools: VS Code and a browser console.
- References mentioned: Course notes on “Walking the DOM” and a sample HTML table.
Rate this summary
Your feedback will help improve summaries.
Improve this summary
Reprocess with a stronger model when the summary feels incomplete or inaccurate.
Translate summary in another language
Ask questions to this video
Chat for follow-up questions, clarifications, and source-backed answers.