HTML, Vanilla JS DOM rendering Flashcards

1
Q

What is DOM?

A

The Document Object Model (DOM) connects web pages to scripts or programming languages. Usually that means JavaScript, but modelling HTML, SVG, or XML documents as objects is not part of the JavaScript language. The DOM model represents a document with a logical tree. Each branch of the tree ends in a node, and each node contains objects. DOM methods allow programmatic access to the tree; with them you can change the document’s structure, style or content. Nodes can have event handlers attached to them. Once an event is triggered, the event handlers get executed.

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

How do we make up our own key for data attributes?

A

use data - key

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

How do we listen for a key-up event?

A

window.addEventListener(‘keydown’, function(e) ….)

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

How would we go about selecting and audio file to play a drum hit on click (vanilla JS)?

A

const audio = document.querySelector(audio[data-key="e.keyCode}"]);

const key = document.querySelector(.key[data-key="e.keyCode}"]);
if(!audio) return;
…to get it playing repeatedly (rewind to start),
audio.currentTime = 0;
audio.play()

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

How to get elements to get a cool style animation?

A

Like in jQuery, we want to add a class.

key.classList.add(‘playing(or desired class’)

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

What happens if we have a setTimeout and another animation in CSS?

A

We fall out of sync. We could instead use a transition-end event

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

Benefits of HTML5

A

Accessibility (more descriptive tags, ie article), Video/Audio Support, Doctype, Cleaner Code, Smarter Storage, Better Interactions, Game Development, Legacy/Cross Browser Support, Mobile, Trending towards the future.

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

what is classList?

A

The Element.classList is a read-only property which returns a live DOMTokenList collection of the class attributes of the element. Using classList is a convenient alternative to accessing an element’s list of classes as a space-delimited string via element.className .

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

Describe how to execute a type ahead using only Vanilla JS.

A

1) Have a JSON file w objects hooked up.
2) Use a built-in method called fetch(). It will return a promise.
3) within the promise, we want to call the json method so that it returns another “blob” of data.
fetch(endpoint)
.then(blob => blob.json())
.then(data => console.log(data))

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

What is fetch( );

A

The Fetch API provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used XMLHttpRequest, but the new API provides a more powerful and flexible feature set.

It returns a promise (something will eventually come back from the fetch - async stuff). It however, does not know what kind of data will be coming back.

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

How to push in individual items from an array into another array (without nesting)

A

Use spread operator. (cities.push(…arrayItems))

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

How to put a variable into a REGEX exp?

A

const regex = new RegExp(wordToMatch, ‘gi’) g means global. i means case insensitive.

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

How do we set up an onChange event in Vanilla JS

A

receiver. addEventListener(‘change’, displayMatchFunction)

receiver. addEventListener(‘keyup’, displayMatchFunction)

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

How do we return HTML syntax within a JS function without JSX?

A

querySelector over the class you want. receiver.innerHTML and set it to a variable that you want to map over. return a string with HTML syntax and join it.

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

Using only Vanilla DOM JS, how would we retrieve input data from a form and display the results on page?

A

1) Create a handlesubmit function.
2) preventDefault
3) set the value of the target class (using document.querySelector(“.classname”)).
4) set the targetclass back to “” after the value has been saved.
5) create an element tag
6) within the .textContent of the created tag, set it to the value of the submitted data.
7) finally, we want to find the actual id of the tag we want to append to. Use getElement by Id and append the submitted data.

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

Web APIs - What is preventDefault()

A

preventDefault() method tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.