Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda