so I want to check if a CSS variable is 0px, and then to console.log a message saying "Make Big". This is the if statement I have tried using:
const root = document.documentElement
const toggleNavButton = document.querySelector('.nav-dropdown');
toggleNavButton.addEventListener('click', () => {
console.log(getComputedStyle(root).getPropertyValue('--mobile-navbar-height'))
if (getComputedStyle(root).getPropertyValue('--mobile-navbar-height') === '0px') {
console.log('Make big');
}
});
And this is the CSS variable:
:root {
--mobile-navbar-height: 0px;
}
This is the HTML:
<html lang="en">
<head>
<title>Frontend - Sign Up</title>
<link rel="stylesheet" href="../styles/styles.css">
<script defer src="../scripts/UI_Manager.js"></script>
</head>
<body>
<header>
<nav class="top-nav">
<ul class="nav-link-container">
<li class="nav-item nav-all">TITLE</li>
<li class="nav-item nav-full">ITEM 1</li>
<li class="nav-item nav-full">ITEM 2</li>
<li class="nav-item nav-full">ITEM 3</li>
<li class="nav-item nav-dropdown">
<span>🍔</span>
</li>
</ul>
</nav>
</header>
</body>
</html>
This is the ouput in the console:
Any help would be appreciated, thanks.
EDIT: Thanks for all your help.
getComputedStyle(root)?