Concept: The HTML DOM
Concept: The HTML DOM
The DOM is represented as a tree structure and each node in the tree is an HTML object with properties and methods that can be accessed and manipulated through JavaScript.
Concept: The HTML DOM
CSS selectors are used to select and style HTML elements in DOM.
<body>
<h1>My Webpage</h1>
<ul class="navbar-menu">
<li><a href="www.example.com">Item 1</a></li>
<li><a href="www.example.com">Item 2</a></li>
<li><a href="www.example.com">Item 3</a></li>
</ul>
<div id="blog-container">
<p>Lorem Ipsum</p>
</div>
</body>
Concept: The HTML DOM
CSS selectors are used to select and style HTML elements in DOM.
Concept: The HTML DOM
CSS selectors are used to select and style HTML elements in DOM.
h1 {
font-size: 24px;
color: #000;
}
.navbar-menu li a {
background-color: #2e5ff6;
padding: 10px;
}
#blog-container p {
padding: 20px;
font-size: 18px;
line-height: 20px;
}
Concept: The HTML DOM
CSS selectors are used to select and style HTML elements in DOM.
Concept: The HTML DOM
JavaScript DOM methods are used to interact with the HTML DOM and manipulate its content. Some of the most commonly used methods include:
document.getElementById
document.getElementsByClassName
document.getElementsByTagName
document.querySelector
document.querySelectorAll
Concept: The HTML DOM
document.getElementById("name-of-id");
document.getElementsByClassName("name-of-class");
document.getElementsByTagName("tag-name");
Concept: The HTML DOM
document.querySelector("selector-pattern");
document.querySelectorAll("selector-pattern");
Concept Practice: DOM Methods
Concept: The HTML DOM
There are several methods available in JavaScript to modify elements in the DOM. Here are a few examples:
innerHTML - used to get or set the HTML content of an element
textContent - used to get or set the text-only content of an element
style - used to get or set the CSS style properties of an element
classList.add(className) - used to add a CSS class to an element
setAttribute(attrName, attrValue) - used to set an attribute on an element
Creating HTML Content with JavaScript