Week 6 Flashcards
DOM stands for _________ _______ ______, it is a data structure that represents all parts of an ____ document
Document Object Model, HTML
The JavaScript object “document” represents the entire ___
DOM
T/F - DOM methods allow programmatic access to the tree
True
A node is an ______ that has properties. Each node in the DOM tree has:
A ____
A________ and their values
C_____ (if any)
object, A name, Attributes, Content
Types of DOM nodes (3)
Element Nodes, text nodes, attribute nodes
Properties of a basic node object:
(hint) 4 parent child related
Childnodes, firstChild, lastChild, parentNode
nodeName, nodeType, nodeValue, textContent
5 Selection methods
get______By__
get_______By_______
get_______ByC________
q___________(________)
q_____________(________)
getElementById(“id”)
getElementsByClassName(“name”)
getElementsByTagName(“name”)
querySelector(“selector”)
querySelectorAll(selector)
Explain this
getElementById(“id”)
returns the DOM node whose id matches the methods parameter
getElementsByClassName(“name”)
returns an array containing all the DOM nodes whose class attribute matches the methods parameter
getElementsByTagName(“name”)
Returns an array of all the DOM nodes whose type is the same as the methods parameter
getElementsByTagName(“footer”)
QuerySelectorAll()
Returns an array containing ALL the DOM nodes that match the CSS selector in the methods parameter
QuerySelector()
Returns the first element found in the DOM that matches the CSS selector in the methods parameter
A manipulation method ______s the right element from the DOM and then it will ______ the right property of this element
Select, change
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
node.prepend(nodes or strings)
node.before(nodes or strings)
node.after(nodes or strings)
node.append(nodes or strings)
node.remove()
Commonly used node properties:
Her definitions:
innerHTML -
textContent -
style -
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.
Commonly used node properties:
Her definitions
className -
tagName -
classNAme - The current value of the element’s class
tagName - The tag name of the element
an _____ is an action, usually caused by a user, that the web browser responds to
event
Event driven programming is a programing style where
code runs only in response to events
Code that runs in response to an event is called an event _______ or event ________
event handler or event listener
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?
object.
It’s often named e.
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
- Identify the source element to listen for an event
- Indicate the event to trigger a response
- Specify the response function(s) to call when the event is triggered
target.addEventListener(event, fucntion)
What is the target, what is the function?
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.
T/F - Good practice is to use the addEventListener() rarely
False.
Good practice is to use the addEventListener() method whenever possible
Common DOM Events for each piece of hardware/software
Mouse Events
Keyboard Events
Form Events
Document/Window events
Click
Keypress
Submit/Focus
load
e.g window.onload = funciton() {
-whatever needs to happen when the page loads
}