- What is the DOM in JavaScript?
Concept: Basics
Explain that DOM = Document Object Model
It represents HTML as a tree structure
JS uses it to interact with web pages
- How do you select an element by ID?
Concept: getElementById()
let heading = document.getElementById("title");
- How do you select elements by class name?
Concept: getElementsByClassName()
let items = document.getElementsByClassName("item");
- What is the difference between querySelector() and querySelectorAll()?
Concept: Modern selectors
document.querySelector(".box"); // first match
document.querySelectorAll(".box"); // all matches
- How do you change text inside an element?
Concept: innerText
document.getElementById("title").innerText = "Hello World";
- How do you change HTML content?
Concept: innerHTML
document.getElementById("box").innerHTML = "Bold Text";
- How do you change CSS styles using JavaScript?
Concept: style
document.getElementById("box").style.color = "red";
- How do you add a click event to a button?
Concept: addEventListener()
document.getElementById("btn").addEventListener("click", function() {
alert("Button clicked!");
});
- How do you create a new element and add it to the page?
Concept: createElement() & appendChild()
let newPara = document.createElement("p");
newPara.innerText = "New paragraph";
document.body.appendChild(newPara);
- How do you remove an element from the DOM?
Concept: remove()
document.getElementById("box").remove();
Top comments (0)