DOM Manipulation Checklist
**************************
- Do you know what DOM is and its use in JavaScript ?
- DOM - Document Object Model - is a programming interface for HTML documents. It is used to represent the page so that programs can change the document structure, style, and content
- DOM is created by the browser when a web page is loaded. In graphical form, it's like a tree of elements also called nodes, which are used to represent every single element on the page. All the DOM of our webpage sits inside the document object. Programmatically, this model allows us to read or even change the content of our page via JavaScript.
Reference:
Adugna: https://youtu.be/6XtDRvdF9M4?t=267
External: https://youtu.be/l-0nPnSvbX8
- Do you know why we need JavaScript for DOM manipulation?
- The main reason we include JavaScript in our HTML is to add instructions on how it should respond to an action taken on the browser. In other words, to add interactivity on the page.
Reference:
Adugna: https://youtu.be/oMq2pLNIeC0?t=1029
- Do you know why we have to understand DOM?
- Your job as a JavaScript front end developer is to select and update the DOM elements when a user interacts with a website. DOM is what lets you do this using JavaScript.
- Do you know some of the actions of DOM in JavaScript?
- Change/Remove HTML elements in the DOM/on the page.
- Change and add CSS styles to elements
- Read and change attributes (href, src, alt), etc.
- Create new elements and insert them into the DOM/page.
- Attach event listeners to elements (click, keypress, submit)
- Do you understand and distinguish the four kinds of nodes in a DOM tree?
Answer:
- Document Node - Represent the entire page which contains multiple elements in it.
- Element Node- Represent each HTML tag that are used in the HTML code.
- Attribute Node - These are nodes to model the attribute of HTML elements, for instance <img src = “ †width = “†alt = “†>
- Text Node - These are the text content of the HTML element.
Reference:
Adugna’s: https://youtu.be/6XtDRvdF9M4?t=954
External: https://www.youtube.com/watch?v=y3itGTCseAk
- Do you know how to select an individual element using getElementById() method?
- getElementById()- method returns the element that contains the name id passed. And in case we do not have any id with that specific name, it returns null.
Reference:
Adugna’s: https://youtu.be/6XtDRvdF9M4?t=3386
- Do you know how to select an individual element using querySelector() method?
- querySelector()-method returns the first Element within the document that matches the specified selector, or group of selectors. If no matches are found, null is returned.
Reference:
Adugna’s: https://youtu.be/6XtDRvdF9M4?t=3863
- Do you know how to select an individual element by traversing between multiple elements?
- You can traverse from one element to another by using properties like parentNode, previousElementSibling, nextElementSibling,firstElementChild and lastElementChild.
Reference:
Adugna’s: https://youtu.be/6XtDRvdF9M4?t=5682
- Do you know how to select multiple elements using getElementsByClassName() method?
- getElementsByClassName()-method returns an HTMLCollection of all those elements containing the specific name class passed.
Reference:
Adugna’s: https://youtu.be/6XtDRvdF9M4?t=4604
- Do you know how to select multiple elements using getElementsByTagName() method?
- getElementsByTagName()-method returns an HTMLCollection of all those elements with the tag name passed.
Reference:
Adugna’s: https://youtu.be/6XtDRvdF9M4?t=4783
- Do you know how to select multiple elements using the querySelectorAll() method?
- querySelectorAll()-method returns all elements in the document that matches a specified CSS selector(s), as a static NodeList object. The NodeList object represents a collection of nodes. The nodes can be accessed by index numbers.
Reference:
Adugna’s: https://youtu.be/6XtDRvdF9M4?t=4604
- Do you know how to alter(change) values and properties?
- Altering a specific text node:You use the property "nodeValue" and “textContent†to access or update content of a text node
- Working with HTML content: when you want to add, update or remove blocks of HTML code from your page, you use the methods like createElement(), innerHTML, textContent, appendChild() and removeChild().
- Working with attributes:when you want to add, update or remove the attribute value of an element, you use the methods like className, classList, id, hasAttribute(), getAttribute(), setAttribute(), removeAttribute().
Reference:
Adugna: https://youtu.be/GnIrZP6-MbE?t=56