Questions About DOM
The following questions are not mandatory.
-
What is the DOM?**
- What does DOM stand for, and what is its purpose in web development?
- Explain the structure of the DOM.
- How does JavaScript interact with the DOM?
- What is the difference between the DOM and the HTML source code?
- What is a DOM node?
-
DOM Node Types**
- How many types of DOM nodes are there, and what are they?
- What is the difference between an Element node and an Attribute node?
- What is a Text node?
- What is the significance of the
nodeTypeproperty? - Describe the differences between
childNodes,firstChild, andlastChild.
-
Selecting Elements with the DOM**
- How do you select a DOM element by its ID?
- What is the difference between
getElementsByClassName()andquerySelectorAll()? - How do you select the first
<p>element in the document using a query selector? - What is returned by
document.getElementsByTagName('p')? - Can you select elements using CSS pseudo-classes with
querySelectorAll()? Give an example.
-
Updating/Modifying DOM Elements**
- How can you change the text content of an HTML element using JavaScript?
- How would you change the
hrefattribute of a<a>tag? - How can you add and remove classes from a DOM element?
- How do you change the CSS styles of an HTML element using JavaScript?
- How would you remove a specific HTML element from the page?
-
Creating Elements**
- How can you create a new
<div>element and add it to the DOM? - How would you add text content to a newly created element?
- How would you set the
classattribute of a new element? - How do you insert a new element as the first child of an existing element?
- How would you create a new
<p>element, add text content to it, and then append it to an existing<div>element?
- How can you create a new
-
Deleting Elements in the DOM**
- How can you delete a specific DOM element?
- How do you remove a child element from a specific parent element?
- How would you remove all child elements of a given parent element?
- What potential issues could arise from not properly managing references when removing elements?
- Can you still interact with a DOM element after it has been removed from the DOM? Why or why not?