DOM 0206 Flashcards

1
Q

Why do we log things to the console?

A

so u can see what ur code’s doing

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

What is a “model”?

A

a model made of objects representing the document (html)

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

Which “document” is being referred to in the phrase Document Object Model?

A

the document in the browser, an html document

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

What is the word “object” referring to in the phrase Document Object Model?

A

*all objects that make the model

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

What is a DOM Tree?

A

a model of a web page in form of a tree

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

Give two examples of document methods that retrieve a single element from the DOM.

A

getElementById( ) - uses value of id attribute
querySelector( ) - this uses css selector or element name etc, returns first matching element

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

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

getElementByClassName( )
querySelectorALL( )

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

Why might you want to assign the return value of a DOM query to a variable?

A

In situations where you want to use it more than once.

storing it will make performance better later so the query doent’ have to be run again

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

What console method allows you to inspect the properties of a DOM element object?

A

console.dir( )
*is dir directory?

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

Why would a

 tag need to be placed at the bottom of the HTML content instead of at the top?
A

Because JavaScript runs from top to bottom … the html needs to be parsed before we get to our js

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

What does document.querySelector() take as its argument and what does it return?

A

takes a css selector , or others, as an argument. it returns the first element

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

What does document.querySelectorAll() take as its argument and what does it return?

A

elements (and others) and returns all nodes with that name

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

what is the defer keyword?

A

it is legacy style, but it allows for full page to load before creating dom tree, NO MATTER WHERE the script tag is located

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

What is the purpose of events and event handling?

A

To run code under specific circumstances

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

Are all possible parameters required to use a JavaScript method or function?

A

no

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

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

add event listener method

E g,

Document. queryselector(class).addeventlistener(‘click’, callbackfunction)

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

What is a callback function?

A

function passed into another as an argument

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

What object is passed into an event listener callback when the event fires?

A

the “event” object

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

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

the specific html element that was interacted with

I guess you could console log it or you could console.dir it

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

What is the difference between these two snippets of code?

snipped A
element.addEventListener(‘click’, handleClick)

Snipped B
element.addEventListener(‘click’, handleClick())

A

the second one will be unfefined
*(review this for as to why)

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

What is the className property of element objects?

A

it allows you to get or update a class name

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

How do you update the CSS class attribute of an element using JavaScript?

A

select element with class name and assign

  • Query selector for getting
  • .className = ‘class’
    I think without the period for the class name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the textContent property of element objects?

A

allows u to access text content in an element

*And change it?

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

How do you update the text within an element using JavaScript?

A

uses textContent property to update it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Is the event parameter of an event listener callback always useful?
I believe it is not only useful but also always necessary
26
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
More complicated because we would have to write some of the code more than once, that is each time we would want to use the code that we could otherwise put inside a variable
27
Why is storing information about a program in variables better than only storing it in the DOM?
it's faster to retrieve, and we don't want to depend on the dom as it's dynamic and changing
28
this (below) is a getter/setter. how do u convert from one to the other? className
(this sets it) $hotButton.className = 'hot-button hot'; vs (this gets it) $hotButton.className;
29
should u use "innterText" method?
no, it's a hacking vulnerability
30
Css. What does the transform property do?
lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model.
31
Give four examples of CSS transform functions.
rotate, scale, skew, or translate
32
what does the space before colon do?: .pokeball-wrapper:first-child .pokeball-wrapper :first-child
without space: first child among pokeball wrapper children, that is this Pokeball rappers siblings with space: first child inside the pokeball wrapper, that is this Pokeball rapper's children *double check to confirm this
33
how do you select items for manipulation with the dom?
Query selector method
34
how do you listen for things on the dom?
Add event listener
35
The transition property is shorthand for which four CSS properties?
delay, duration, easing, delay
36
do you apply transitions to the class or pseudo class?
apply it to the class for full functionality
37
What event is fired when a user places their cursor in a form control?
the "focus" event
38
What event is fired when a user's cursor leaves a form control?
*the "blur" event
39
What event is fired as a user changes the value of a form control?
the input event
40
What event is fired when a user clicks the "submit" button within a
?
the "submit" event
41
What does the event.preventDefault() method do?
prevents default behavior, *and in the case today it prevents the page from resetting after submitting a form
42
What does submitting a form without event.preventDefault() do?
it would reload the page
43
What property of a form element object contains all of the form's controls.
.elements
44
What property of a form control object gets and sets its value?
.value
45
What is one risk of writing a lot of code without checking to see if it works so far?
wasting time!
46
What is an advantage of having your console open when writing a JavaScript program?
so you can see functionality thru console logs etc.
47
study and explain this code: function handleFocus(event) { console.log('focus event fired'); console.log(event.target.name); } function handleBlur(event) { console.log('blur event fired'); console.log(event.target.name); } function handleInput(event) { console.log(event.target.name, event.target.value); } var inputUserName = document.querySelector('#user-name'); var inputUserEmail = document.querySelector('#user-email'); var textArea = document.querySelector('#user-message'); inputUserName.addEventListener('focus', handleFocus); inputUserName.addEventListener('blur', handleBlur); inputUserName.addEventListener('input', handleInput); inputUserEmail.addEventListener('focus', handleFocus); inputUserEmail.addEventListener('blur', handleBlur); inputUserEmail.addEventListener('input', handleInput); textArea.addEventListener('focus', handleFocus); textArea.addEventListener('blur', handleBlur); textArea.addEventListener('input', handleInput);
48
Does the document.createElement() method insert a new element into the page?
49
How do you add an element as a child to another element?
50
What do you pass as the arguments to the element.setAttribute() method?
51
What steps do you need to take in order to insert a new element into the page?
52
What is the textContent property of an element object for?
53
Name two ways to set the class attribute of a DOM element.
* .setAttribute or .setClassName?
54
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
55
Give two examples of media features that you can query in an @media rule.
min-width max-width
56
Which HTML meta tag is used in mobile-responsive web pages?
*viewport?
57
What is the event.target?
tells you what was interacted with
58
Why is it possible to listen for events on one element that actually happen its descendent elements?
59
What DOM element property tells you what type of element it is?
tag name
60
What does the element.closest() method take as its argument and what does it return?
61
How can you remove an element from the DOM?
using the remove( ) method
62
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
*add to parent to catch what happens on children
63
What is the event.target?
64
What is the affect of setting an element to display: none?
it is treated as having disappeared (not being there)
65
What does the element.matches() method take as an argument and what does it return?
*class, id, element?
66
How can you retrieve the value of an element's attribute?
the getAttribute( ) method
67
At what steps of the solution would it be helpful to log things to the console?
whenever possible, before writing too much more code
68
If you were to add another tab and view to your HTML, but you didn't use event delegation, how would your JavaScript code be written instead?
target the children
69
If you didn't use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
more conditional statements (e.g. if else, switch etc.)
70
What is a breakpoint in responsive Web design?
the point at which a css rule activates based on parameters set
71
What is the advantage of using a percentage (e.g. 50%) width instead of a fixed (e.g. px) width for a "column" class in a responsive layout?
it responds to changes in screen size / different screen sizes
72
If you introduce CSS rules for a smaller min-width after the styles for a larger min-width in your style sheet, the CSS rules for the smaller min-width will "win". Why is that?
all else equal, selectors lower in the document are higher in priority. that is, source order
73
should design begin with mobile or desktop screens?
you should perhaps start with mobile because it's easier to make things for bigger from smaller screens than vice versa side note, min width is as screen grows, and what u use when u start with designing for mobile. and vice versa.
74
what do these do? git stash git stash apply
git stash saves a copy and puts it aside git stash apply brings that previous copy back
75
how do you get code which spills out the window to fit?
ctrl + z
76
What is JSON?
JavaScript Object Notation (JSON) is an extremely common data interchange format used to send and store information in computer systems. It is is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa). You'll come across it quite often,
77
What are serialization and deserialization?
Serialization is the process of turning an object in memory into a stream of bytes (1s and 0s) so you can do stuff like store it on disk or send it over the network. Deserialization is the reverse process: turning a stream of bytes into an object in memory.
78
Why are serialization and deserialization useful?
*so it can be stored and sent. *it's more efficient because it turns it into a simpler, more generic format?
79
How do you serialize a data structure into a JSON string using JavaScript?
use the JSON.stringify(books) e.g. var books = [ { isbn: '1234567', title: 'book one', author: 'author one' }, { isbn: '234567', title: 'book two', author: 'author two' } ]; JSON.stringify(books)
80
How do you deserialize a JSON string into a data structure using JavaScript?
use: JSON.parse( ) call the method using a string of the data structure, e.g. JSON.parse('{ "id": 567, "name": "Jon Doe" }')
81
How do you store data in localStorage?
use the setItem method on the localStorage object, e.g. localStorage.setItem('javascript-local-storage', todosJSON)
82
How do you retrieve data from localStorage?
use the getItem method on the localStorage object, e.g. localStorage.getItem('javascript-local-storage');
83
What data type can localStorage save in the browser?
a JSON string allows you to access a Storage object for the Document's origin; the stored data is saved across browser sessions.
84
When does the 'beforeunload' event fire on the window object?
The beforeunload event is fired when the window, the document and its resources are about to be unloaded. https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
85
what is event handling?
the three steps involved in getting an event to trigger JS code those are: 1 select element 2 specify event 3 call the code
86
how do you change the text content of a node?
e.g. document.getElementById('divA').textContent = 'This text is different!';
87
what does this tag do? *from css-media-queries exercise mdn doc: https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag
it sets the scale to 100% on mobile devices, not manipulating it to scale up or down as it usually does in the default mode
88
what does this do: e.target.closest('.task-list-item') ancestor element.
it gets the event's closest ancestor with that class name, in this case it's task-list-item. if the event is a 'click' on a button element, which is a child of an element with '.task-list-item class, the clicking of the button would get that element (class: task-list-item). it could then be removed by using the .remove() method
89
what is this code doing? var taskList = document.querySelector('.task-list'); taskList.addEventListener('click', taskListCallback); function taskListCallback(e) { console.log('event target:', e.target); console.log('event tagname:', e.target.tagName); if (e.target && e.target.nodeName === 'BUTTON') { console.log(taskList.closest('.task-list-item')); e.target.closest('.task-list-item').remove(); } } OR THE BELOW(THEY ARE DOING THE SAME THING BUT BELOW HAS ONE LINE SEPARATED INTO A VARIABLE var taskList = document.querySelector('.task-list') taskList.addEventListener('click', callBackFunction); function callBackFunction(e) { console.log('event target:', e.target); console.log('event tagname:', e.target.tagName); if (e.target.tagName === 'BUTTON') { var closestAncestor = e.target.closest('.task-list-item'); console.log(closestAncestor); e.target.closest('.task-list-item').remove(); } } https://photos.app.goo.gl/bBR6vCTogWtTbkKu9
you know if you succeeded/failed
90
read and explain this dom-creation code https://photos.app.goo.gl/oLMaEFW8iumAXgFJ8
https://photos.app.goo.gl/oLMaEFW8iumAXgFJ8
91
read and explain this javascript-view-swapping code JS https://photos.app.goo.gl/UCmjRdCDEtwipxoA8 HTML https://photos.app.goo.gl/K2LqJybHX2PxfD3P9