DOM Structure Explained

Day 15/100 of JavaScript 🚀 Today’s topic : DOM Structure The DOM represents a web page as a tree structure where each element is a node ❕Types of nodes - Document → root of the page - Element → HTML tags ("div", "p", etc.) - Text → content inside elements - Attribute → properties like "id", "class" ❕Tree relationships - Parent → element containing another element - Child → element inside another - Siblings → elements at the same level ➡️ Example <body> <div id="parent"> <p>Child 1</p> <p>Child 2</p> </div> </body> const parent = document.getElementById("parent"); console.log(parent.children); -> HTMLCollection of children console.log(parent.firstElementChild); console.log(parent.lastElementChild); ❕Traversing DOM parent.parentElement; -> access parent parent.children; -> access children parent.nextElementSibling; ->next sibling Understanding DOM structure helps in navigating and manipulating elements efficiently #Day15 #JavaScript #100DaysOfCode

To view or add a comment, sign in

Explore content categories