dom manipulation Flashcards
What is the className property of element objects?
Used to access or change the class of an element
How do you update the CSS class attribute of an element using JavaScript?
var $hotButton = document.querySelector('.hot-button'); Access the node for the class and store in a variable
$hotButton.className = ‘hot-button cold’
Use the className method of the variable used to access the node and assign a new value
What is the textContent property of element objects?
Used to access the text content of an element, to update or change.
How do you update the text within an element using JavaScript?
var $clickCount = document.querySelector('.click-count'); Use the query selector to select a class and set to a variable
$clickCount.textContent = ‘Clicks: ‘ + timesClicked;
use the textContent method on the variable and assign a value to change it
Is the event parameter of an event listener callback always useful?
No
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
Complicated, would have to find a different way to constantly update the number
Why is storing information about a program in variables better than only storing it in the DOM?
javascript is easier to use, and avoid using the dom if we can help it