Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
How can i make dark mode for nav bar with javascript?

i m trying to implement dark mode to my website project, i did it for the body part with js, but i can't do it for navigation bar using 'navbar' class. Here is my js codes:

function darkMode() {
var element = document.body;
var navbar = document.getElementById("navbar");

element.classList.toggle("dark-mode");

As you can see it's just for the body element. When i try to create variable for navbar it doesn't work.

    <div id="navbar" class="navbar">
    <div class="navbar_left">
        <a href="index.php">
            <img src="img/logo_transparent.png">
        </a>
    </div>

    <form class="navbar_mid" action="./action_page.php" method="get">
        <input type="text" id="search" placeholder="Search.." name="search">
        <button id="searchbutton" type="submit"><i class="fa fa-search"></i></button>
    </form>
    <div class="navbar_right">
        <?php echo $multipleBtn; ?>
    </div>
</div>

This is my navbar codes. If i can write a correct js codes i can handle the css codes. Can you help me?

UPDATE

I tried body.dark-mode #navbar {background color:#ddd;} and it actually worked. But only for my index.php file as you can see below:

enter image description here

but my other php file it looks like this:

enter image description here

I really checked the codes twice, css 's files are the same for both pages and implemented for both. Could you help me with this problem?

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!