DOM Manipulation Flashcards

1
Q

What does DOM stand for?

A

Document Object Model

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

What does the following code do?

document.getElementById(‘aboutMe’);

A

This will select the element with the id of aboutMe from the HTML document.

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

What does the following code do?

document.querySelector(‘ol li’);

A

This will select the first li element inside of the first ol element.

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

What does the following code do?

document.querySelectorAll(‘p’);

A

This will select all paragraph elements within the HTML document.

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

What will the following code do?

let liTag = document.getElementsByTagName('li');
for(tag of liTag) {
  tag.style.fontFamily = 'cursive';
}
A

This will change the font family to cursive for each item with the li tag.

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

What are two methods that can change text on the DOM

A
  1. ) innerText : specifies the text content of the specified node
  2. ) innerHTML : specifies the HTML content of an element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the syntax for creating a new h1 element on a page?

A

document.createElement(‘h1’)

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

What will the following code display on the page?

let toDoTitle = document.createElement('h2');
let toDoDiv = document.getElementById('toDoDiv');

toDoDiv.appendChild(toDoTitle);
toDoTitle.innerText = ‘Needs to be done’;

A

This will place a new h2 element within the div with an id of “toDoDiv”. The h2 element text will be “Needs to be Done”
The only thing that will currently be displayed on the page is:

Needs to be Done

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

What document method can you use to select the first matching element within a document?

A

querySelector( )

Example Usage: 
document.querySelector('h1');
//this will select the first h1 element that appears in a document
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What document method can you use to select all matching elements within a document?

A

querySelectorAll( )

Example Usage:
document.querySelectorAll('li');
//this will select all elements within a document that have an li tag
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What method can you use to select an element with its id?

A

getElementById( )

Example Usage:
document.getElementById('animals');
//this would select the element with the id of 'animals'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Using this code to start, what would you need to do to add styling that changes the font color to blue and align the text to the center?

let para = document.querySelectorAll(‘p’);

A

let para = document.querySelectorAll(‘p’);

para. style.textAlign = ‘center’;
para. style.color = ‘blue’;

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