Week 6 Flashcards

1
Q

DOM stands for _________ _______ ______, it is a data structure that represents all parts of an ____ document

A

Document Object Model, HTML

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

The JavaScript object “document” represents the entire ___

A

DOM

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

T/F - DOM methods allow programmatic access to the tree

A

True

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

A node is an ______ that has properties. Each node in the DOM tree has:
A ____
A________ and their values
C_____ (if any)

A

object, A name, Attributes, Content

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

Types of DOM nodes (3)

A

Element Nodes, text nodes, attribute nodes

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

Properties of a basic node object:
(hint) 4 parent child related

A

Childnodes, firstChild, lastChild, parentNode

nodeName, nodeType, nodeValue, textContent

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

5 Selection methods

get______By__
get_______By_______
get_______ByC________
q___________(________)
q_____________(________)

A

getElementById(“id”)
getElementsByClassName(“name”)
getElementsByTagName(“name”)
querySelector(“selector”)
querySelectorAll(selector)

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

Explain this

getElementById(“id”)

A

returns the DOM node whose id matches the methods parameter

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

getElementsByClassName(“name”)

A

returns an array containing all the DOM nodes whose class attribute matches the methods parameter

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

getElementsByTagName(“name”)

A

Returns an array of all the DOM nodes whose type is the same as the methods parameter

getElementsByTagName(“footer”)

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

QuerySelectorAll()

A

Returns an array containing ALL the DOM nodes that match the CSS selector in the methods parameter

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

QuerySelector()

A

Returns the first element found in the DOM that matches the CSS selector in the methods parameter

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

A manipulation method ______s the right element from the DOM and then it will ______ the right property of this element

A

Select, change

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

Manipulation methods - Create Node:
Insert and removal:
node._______(_____ __ ______) - Insert into node at the beginning
node.before(nodes or strings) - Insert right before node
node._____(nodes or strings) - Insert right after node
____._____(nodes or strings) - Add the new node to the existing DOM tree
____.______() - remove nodes

A

node.prepend(nodes or strings)
node.before(nodes or strings)
node.after(nodes or strings)
node.append(nodes or strings)
node.remove()

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

Commonly used node properties:
Her definitions:

innerHTML -
textContent -
style -

A

innerHTML - all of the content of an element (text and tags). It replaces content but retains attributes
textContent - gets the content of all elements
style - They style attribute of the element

Better context:
InnerHTML - Can be used to get/set the content of the element it is used on. Whatever is inside is replaced but attributes are retained.

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

Commonly used node properties:
Her definitions

className -
tagName -

A

classNAme - The current value of the element’s class
tagName - The tag name of the element

17
Q

an _____ is an action, usually caused by a user, that the web browser responds to

18
Q

Event driven programming is a programing style where

A

code runs only in response to events

19
Q

Code that runs in response to an event is called an event _______ or event ________

A

event handler or event listener

20
Q

When an event occurs an event ______ is created and passed to the event listener. The event listener/handler can access this event object by including it as an argument to the callback function.

By convention, what is the event object parameter often named?

A

object.

It’s often named e.

21
Q

We can use JavaScript to attach functions to elements when an event occurs. To do we need to:
1. Identify
2. Indicate
3. Specify the

A
  1. Identify the source element to listen for an event
  2. Indicate the event to trigger a response
  3. Specify the response function(s) to call when the event is triggered
22
Q

target.addEventListener(event, fucntion)

What is the target, what is the function?

A

The target is the HTML element you want to add the event handler to. The function is the functions to run when the event is detected.

23
Q

T/F - Good practice is to use the addEventListener() rarely

A

False.

Good practice is to use the addEventListener() method whenever possible

24
Q

Common DOM Events for each piece of hardware/software
Mouse Events
Keyboard Events
Form Events
Document/Window events

A

Click
Keypress
Submit/Focus
load

e.g window.onload = funciton() {
-whatever needs to happen when the page loads
}

25
3 types of errors in JS GO
Syntax, Runtime, Logic
26
Runtime error vs logic error GO
Runtime - When a valid piece of code tries to do something that it's not allowed to Logic - When there are bugs built into our code and we do not get our intended results (often runs but results are undesirable)
27
T/F - The try statement allows you to define a block of code to be tested for errors while it is being executed
True Syntax: try { }
28
T/F - The catch statement allows you to define a block of code to be executed, if an error occurs in the try block
True Syntax: catch(err){ }
29
A throw statement allow you to create a custom error. What is the exception compatible with?
A string, number, boolean, or object Syntax: if (StartIndex<0){ throw "startIndex is less than 0." }
30
T/F - The finally statement executes code after the try and catch statements if they pass
False. The finally statement executes code after the try and catch statements regardless of the result
31
T/F - Regular expression - RegEx is a sequence of characters that forms a search pattern.
True. search() and replace() can be used with RegEX strings
32
T/F - RegEx is used for form validation, as with Regex you can specify valid patterns for field entires, such as email addresses or phone numbers
True
33
JavaScript RegEX: What do these operators mean/do? . * + ? [ ]
. matches any character except \n * means 0 or more occurences + means 1 or more occurences ? means 0 or 1 occurences [ ] group characters into a character set, will match any single character from the set
34
Inside a character set, specify a range of chars with - What do these do? /[a-z]/ - /[a-zA-Z0-9]/
/ [a-z]/ - matches any lowercase letter /[a-zA-Z0-9]/ matches any lowercase letter or number
35
T/F - ^ inside of RegEx negates a character set
True /[^abcd]/ would match any character BUT the ones listed
36
RegEX - What do | and () mean?
| means OR () are for grouping. matches enclosed characters in exact order anywhere in a string