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

264
Vistas
Django - classList.toggle is not working in django template

I am trying to animate a hamburger menu to transform into an 'x' when it is clicked. The javascript works in a normal html file, but when integrated with django for some reason it doesn't work. (Also I have checked that the javascript is linked properly to the django template.)

const hamburger = document.querySelector(".hamburger");


hamburger.addEventListener("click", menu);

function menu() {
    hamburger.classList.toggle("active");
}
<link rel="stylesheet" href="{% static 'lng/css/navbar.css' %}" />
<link rel="stylesheet" href="{% static 'lng/css/main.css' %}" />
<script src="{% static 'lng/js/main.js' %} " type="text/javascript"></script>

<button class="hamburger">
          <span class="bar"></span>
          <span class="bar"></span>
          <span class="bar"></span>
        </button>
.hamburger {
    display: inline;
    position: relative;
    z-index: 1;
    user-select: none;
    appearance: none;
    border: none;
    outline: none;
    cursor: pointer;
    transition: 0.1s;
  }
  
  
.hamburger span {
    display: block;
    width: 33px;
    height: 4px;
    margin-bottom: 5px;
    position: relative;
    background-color: var(--dark);
    border-radius: 6px;
    z-index: 1;
    -webkit-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out;
  }

.hamburger:active .bar:nth-child(2){
        opacity: 0; 
    }

    .hamburger:active .bar:nth-child(1){
        transform: translateY(8px) rotate(45deg);

    }

    .hamburger:active .bar:nth-child(3){
        transform: translateY(-8px) rotate(-45deg);

    }```
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