Lecture 4: JavaScript: DOM Flashcards

1
Q

Document Object Model

A

The DOM is how programs can access and modify HTML

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

How DOM sees HTML

A

The HTML DOM views an HTML doc as a tree structure
Each node in tree is an HTML element

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

Is DOM static?

A

The DOM is NOT STATIC, It is live and up to date
Modifying the DOM means the web page that is displayed is modified

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

To manipulate an element inside the DOM, you need to…

A

Select it first.

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

querySelector()

A

Which returns a reference to the First match. E.G. Let element1 = document.querySelector(“h1”

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

querySelectorAll():

A

returns a list of all matching element nodes

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

Use CSS selectors

A

Basic, combinators, and group all works, but you cannot use pseudo classes.

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

Ways to change HTML Elements

A

Let element = document.querySelector(“.container p”)
element.style.backgroundColor = “yellow”
element.textContent = “I don’t like blind text.”
element.innerHTML = “I don’t like <strong>blind</strong> text.

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

Add CSS Dynamically

A

element.classList.add(‘classname’)
You can really add any attribute: element.setAttribute(‘id’, ‘id_Name’)

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

Creating an Element

A

Create a new element: createElement(‘tag_Name’)
Then add it to the DOM by appending to an element: element.appendChild()

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

Remove Element

A

Call remove, super simple.
element.remove().
Example
Let hello = document.querySelector(“h2”);
hello.remove();

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

Including Javascript

A

<script src = “../js/script.js”></script>

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

Defer

A

Defer keyword when your code requires the HTML structure to be loaded.

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