Goal: Practice accessing the DOM by using the document
methods we learned about in the previous lesson.
let
or const
(or var
) to declare a variable? Why is that bad?let bunnyName = "Flopsy";
function hippityHoppity() {
window.alert(bunnyName);
bunnyName = "Cottontail";
}
hippityHoppity();
window.alert(bunnyName);
let bunnyName = "Flopsy";
function hippityHoppity() {
let bunnyName = "Mopsy";
window.alert(bunnyName);
bunnyName ="Cottontail";
}
hippityHoppity();
window.alert(bunnyName);
Clone down the Cookie Recipe HTML and open it in your web browser. Then, use the DevTools console to practice accessing different DOM elements by working through each prompt below. Reference the previous lesson "Accessing the DOM" as needed. You should be able to complete all of the following prompts with just the information in the lesson.
window.document.querySelector()
.<em>
element within the paragraph element (using the correct CSS selector) with window.document.querySelector()
.Switch who's driving and observing, and complete the remaining prompts:
<body>
element and all of its contents by accessing the correct window.document
property.id
attribute with window.document.getElementById()
.<ul>
element by targeting it with its class name (using the correct CSS selector) with window.document.querySelector()
.