Intro Flashcards
HTML creates the skeleton of a webpage, and JavaScript introduces ____
interactivity
The SCRIPT element has an opening and closing tag. You can embed JavaScript code inbetween __
the opening and closing SCRIPT tags.
You link to external JavaScript files with the ___
src attribute in the opening SCRIPT tag.
By default, scripts are loaded and executed as soon as the HTML parser encounters them in the HTML file, the HTML parser waits to load the entire script before ___
proceeding to parse the rest of the page elements.
The defer attribute ensures that __
the entire HTML file has been parsed before the script is executed.
The async attribute will allow the HTML parser to __
continue parsing as the script is being downloaded, but will execute immediately after it has been downloaded.
document.getElementbyId(‘sign’).hidden = true;
Hide an element b/c it doesn’t need to be loaded initially (not the same as setting CSS visibility property to hidden)
let paragraph = document.querySelector('p'); document.body.removeChild(paragraph);
Remove 1st par in doc
const parent = document.querySelector("#more-destinations"); const child = document.querySelector("#oaxaca"); parent.removeChild(child);
Select the element with the ID oaxaca and save it to a variable.
Select its parent, assigned an ID of more-destinations.
Remove the element using the .removeChild() method and passing in the variable containing the oaxaca element.
let element = document.querySelector(“button”);
function turnButtonRed (){ element.style.backgroundColor = "red"; element.style.color = "white"; element.innerHTML = "Red Button"; }
element.onclick = turnButtonRed;
Add interactivity to the button. Set the button background to red. Set the button font color to white. Connect the button element to the style function for a click event. Clicking the button will change the style.
Define parent node.
In the DOM hierarchy, parent and children relationships are defined in relation to the position of the root node.
A parent node is the closest connected node to another node in the direction towards the root.
Define child node
In the DOM hierarchy, parent and children relationships are defined in relation to the position of the root node.
A child node is the closest connected node to another node in the direction away from the root.
What’s the DOM property that lets you access the parent and child nodes for each DOM element (including the first child)?
Each DOM element node has a .parentNode and .children property. The property will return a list of the element’s children and return null if the element has no children.
The .firstChild property will grant access to the first child of that parent element.
What does DOM stand for?
Document Object Model
Syntax for keypress event?
eventTarget.onkeypress = eventHandlerFunction;