DOM manipulation Flashcards

1
Q

List main types in Dom node hierarchy and provide examples

A
  • EventTarget : window, XMLHttpRequest
  • Node: document, Text, Comment
  • Element: includes HTMLElements, SVGElements
  • HTMLElement: <i>, <b>;
  • Speficic HTML Elements types like HTMLButtonElement: <button>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

EventTarget type

A

An EventTarget is the most generic of DOM types. It represents objects that can receive events and may have listeners for them.

In a nutshell all you can do with it is add event listeners, remove them, and dispatch events.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Node type

A

It represents a node on the DOM tree.

All objects that implement Node functionality are based on one of its subclasses. Most notable are Document, Element, and DocumentFragment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Element type

A

Element is the most general base class from which all element objects (i.e. objects that represent elements) in a Document inherit. It only has methods and properties common to all kinds of elements. More specific classes inherit from Element.

For example, the HTMLElement interface is the base interface for HTML elements, while the SVGElement interface is the basis for all SVG elements. Most functionality is specified further down the class hierarchy.

Languages outside the realm of the Web platform, like XUL through the XULElement interface, also implement Element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

HTMLElement type

A

The HTMLElement class represents any HTML element. Some elements directly implement this interface, while others implement it via an interface that inherits it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Document interface

A

The Document interface represents any web page loaded in the browser and serves as an entry point into the web page’s content, which is the DOM tree.

The DOM tree includes elements such as <body> and <table>, among many others. It provides functionality globally to the document, like how to obtain the page’s URL and create new elements in the document.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a nodeList ?

A

A nodeList is an array of elements, like the kind that is returned by the method document.querySelectorAll(). Items in a nodeList are accessed by index in either of two ways:

  • list.item(1)
  • list[1]

These two are equivalent. In the first, item() is the single method on the nodeList object. The latter uses the typical array syntax to fetch the second item in the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

NodeListOf type

A

The (document.querySelectorAll().) definition returns a new type: NodeListOf. This return type is essentially a custom implementation of the standard JavaScript list element. Arguably, replacing NodeListOf<E> with E[] would result in a very similar user experience. NodeListOf only implements the following properties and methods: length, item(index), forEach((value, key, parent) => void), and numeric indexing. Additionally, this method returns a list of elements, not nodes, which is what NodeList was returning from the .childNodes method. While this may appear as a discrepancy, take note that interface Element extends from Node.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly