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

107
Views
Responsive Hamburger Menu is not working on Mobile when Clicked

I have created my Responsive Hamburger menu in React. It works fine on Desktop however the hamburger doesn't drop when clicked, it shows this error when clicked ::

TypeError: Cannot read properties of null (reading 'classList')
hamClick
src/hamburger.js:24
  

    21 | 
      22 | const hamClick = (e) => {
      23 |     e.preventDefault();
    > 24 |     if(header.classList.contains('open')){//close hamburger
         | ^  25 |         body.classList.remove('noscroll');
      26 |         header.classList.remove('open');
      27 |         fadeElems.forEach(function(element){

THIS is my code for the Hamburger functionality;;

import React from 'react';

import "./scss/animations.scss";
import './scss/header.scss';
import './scss/mixins.scss';




const Hamburger = () => {

    const btnHamburger = document.querySelector('#btnnHamburger');

    const body = document.querySelector('body');

    const header = document.querySelector('.header');

    const overlay = document.querySelector('.overlay');

    const fadeElems = document.querySelectorAll('.has-fade');
    
    const hamClick = (e) => {
        e.preventDefault();
        if(header.classList.contains('open')){//close hamburger
            body.classList.remove('noscroll');
            header.classList.remove('open');
            fadeElems.forEach(function(element){
                element.classList.remove('fade-in');
                element.classList.add('fade-out');
            });    
        }
        else{//open hamburger
            body.classList.add('noscroll');
            header.classList.add('open');
            fadeElems.forEach(function(element){
                element.classList.add('fade-in');
                element.classList.remove('fade-out');
            });   
        }
    }


    return(
        <a id="btnnHamburger" className="header__toggle hide-for-desktop" href="#" onClick={hamClick}>
            <span></span>
            <span></span>
            <span></span>
        </a>
    )
}

export default Hamburger;

Please can you help me understand what I need to do correctly

about 4 years ago · Juan Pablo Isaza
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!