Dev Board

Blogs

Question-1: What are the different ways to select an element in the DOM?

Answer-1: The different way to select an element in the Dom is 'Id', 'Class Name', 'Tag Name', 'Query Selector', 'Query Selector All ' etc.

Question-2: What is the difference between InnerHTML, InnerTEXT, and textContent?

Answer-2: The difference between InnerHTML, InnerTEXT, and textContent is InnerHTML use the text with HTML tags inside an element, InnerTEXT visible text only and also hidden elements, and the textContent is all text, ignores HTML tags, includes hidden text and very fast.

Question-3: What is event delegation in the Dom?

Answer-3: The event delegation in the dom is attaching a single event listener to a parent to handle events on its child elements, using event bubbling.

Question-4: What is event bubbling in the Dom?

Answer-4: The event bubbling in the Dom is when an event occurs on a child element, it propagates upward to its parent elements, triggering any listeners on them, all the way to the root.

Question-5: How do you create, add and remove elements using javascript?

Answer-5: We can create, add and remove elements using javascript:

Create an Element:

let newDiv = document.createElement("div");

newDiv.textContent = "Hello World";

Add an Element:

document.body.appendChild(createElement);

Add an Element:

let elementRemove = document.getElementById("my element");

elementRemove.remove();