DevBoard

Back to Desk

Blogs

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

Answer: We can select an element by multiple ways, such as getElementById(), querySelectorAll(), getElementsByClassName(), querySelector() etc.

Question-2: What is the difference between innerHTML, innerText, and textContent ?

Answer: innerHTML stands for HTML content inside an element, including HTML tags. innerText stands for sets the visible text inside an element and textContent sets the text content inside an element, including hidden elements.

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

Answer: Event Delegation is a technique in JS where a single parent element handles events for multiple child elements using event bubbling.

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

Answer: Event bubbling is a system in the DOM where an event starts from the target element and propagates up to its parent elements.

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

Answer: We can dynamically create, add, and remove elements using the DOM such as: for creating element we can use: document.createElement(), for add elements we can use, appendChild(), append() etc. for remove elements we can use, removeChild() or remove().