Important FAQ

What is the document Object Model(DOM)?

The Document Object Model (DOM) is a model that represents the structure and content of web document as a collections of objects.

How do you select an element from the Dom?

To select elements in the DOM, we use getElementById()where we need to get unique id, another one is getElementsByClassName() to select a specific class name or another is querySelector() to select an element using a CSS Selector that can combine ID,Class,tag name and attributes

What is the event delegation in the context of the DOM,and Why is it useful?

Event delegation is a mechanism where we attach a single event listener to a parent element allowing it to handle events triggered on any child elements. We delegate the event handling to the parent element instead of attaching the listener to each individual child.Its useful because it improves performance by reducing event listeners and simplifying code for large and dynamic lists.

How do you manipulate an element's attribute and style using the DOM?

we manipulate the attribute an element and style using the DOM we use getAttribute() to get the value of specific attributed. Then we use setAttribute() to set the value of specific attributed and then we remove the specific Attribute using removeAttribute() . Then where needed to the style we access the defines inline css selector or method.