Document Object Model (DOM) Flashcards

1
Q

Adding Javascript to…

A

Websites

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

Adding Inline Javascript (NOT GOOD PRACTICE. DON’T USE INLINE JS)

A

Inside the , add a onload=” ”

Example

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

Internal Javascript

A

Include a inside of the html

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

External Javascript

A

Include a with a src=” ”

The placement of the with the .js link matters!
Include CSS in the beginning, inside the
Include JavaScript at the bottom, just before the closing tag

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

Intro to the Document Object Model

A

Catalogs a webpage into individual models/objects where we can alter/manipulate its behaviour and style

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

Document is the root of the webpage

A

document.firstElementChild;

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

HTML Root of web page

A

document. firstElementChild.firstElementChild;

document. firstElementChild.lastElementChild;

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

Selecting HTML Elements with…

A

JavaScript

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

GetElementBy

A

(Broad selector)

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

Get elements by tag name (li, ul, h1, ….)

A

document.getElementsByTagName(< tag >);

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

Get elements by class name

A

document.getElementsByClassName(< className >);

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

Get element by id

A

document.getElementById(< id >);

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

Query Selector

A

(More complex and precise selector)

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

document.querySelector(< CSS Selector >);

A

Returns a singular html element

If the query selector obtains multiple elements, the querySelector only returns the first element

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

document.querySelectorAll( < CSS Selector > );

A

Returns a list of all the html elements that match the CSS Selector

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

Manipulating and Changing Styles of HTML Elements with JavaScript

A

Properties may, and often are, different than the css property.
To set the value, have to include the property in “ “
Changing style
.style. = “”;
Changing color
.style.color = “< color >”;

17
Q

Separation of Concerns: Structure vs Style vs Behavior

A

CSS files should only be in charge of styling a webpage.
So we shouldn’t use DOM - Javascript to modify the style of a web page.
What we can do is, include a style modifier in the CSS file, and using DOM we can add a new class property for the .classList to add/modify styling of a html element.
.classList
Returns a list of the classes that are attached to the element
We can then add properties to the list, to further add new properties for a html element
.classList.add();
Add a new CSS style property
.classList.remove();
Remove a CSS style property
.classList.toggle();
Toggle’s a CSS style property on/off.

18
Q

Text Manipulation and the Text Content Property

A
.textContent
Returns the actual text string value
.innerHTML
Returns the html code
Can also modify the html
19
Q

Manipulating HTML Element Attributes

A

Attributes consist of things like, class=, href=, src=, …
.attributes
Returns the mapping of all the attributes
.getAttribute(“ < Attribute to get > ”);
.setAttribute(“ < Which attribute to change> ”, “ < Value to change the attribute to > ”);