After successfully completing the HTML and CSS part, I hit a roadblock with JavaScript. I'm struggling to figure out how to create a button that can toggle the visibility of text when clicked.
An error message keeps popping up in the console stating that getElement
is not defined. I attempted using getElementByClassName
, but the issue persists.
The console displays
Uncaught ReferenceError: getElement is not defined
as well as for getElementByClassName
.
--
In this scenario:
nav-btn
refers to the button responsible for toggling the text
nav-links
indicates the text that should appear or disappear
--
The JavaScript snippet provided is as follows:
const links = getElement(".nav-links")
const navBtn = getElementByClassName('nav-btn')
links.style.display = 'none';
navBtn.onclick = function () {
if (links.style.display !== "none") {
links.style.display = "none"
} else {
links.style.display = "block"
}
}
How can I modify this code to achieve the desired functionality?
Furthermore, how should I address the undefined getElement
issue?