My goal is to have the text "open" displayed when the navigation bar is not visible, and when it is visible, the text "open" should be hidden. I am new to HTML and JavaScript, and I wrote the following code, but it is not working as expected. Can someone please help me identify what is wrong?
var nav = document.getElementById("Navbar");
var b = document.getElementById("Body");
var open = document.getElementById("Open");
var close = document.getElementById("Close");
function openNav() {
nav.style.width = "250px";
b.style.marginLeft = "250px";
check();
}
function closeNav() {
nav.style.width = "0px";
b.style.marginLeft= "0px";
check();
}
function check() {
if (nav.style.width == "0px") {
close.style.display = "none";
open.style.display = "block";
} else {
open.style.display = "none";
close.style.display = "block";
}
}
Script update
var nav = document.getElementById("Navbar");
var b = document.getElementById("Body");
var open = document.getElementById("Open");
var close = document.getElementById("Close");
function openNav() {
nav.style.width = "250px";
b.style.marginLeft = "250px";
check();
}
function closeNav() {
nav.style.width = "0px";
b.style.marginLeft= "0px";
check();
}
function check() {
if (nav.style.width == "0px") {
close.style.display = "none";
open.style.display = "block";
} else {
open.style.display = "none";
close.style.display = "block";
}
}
what i'm getting
Open Navbar all good here Closed Navbar not good, Open button is invisible