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

101
Vistas
How do I fix my SideBar to open and close?

I am trying to get a SideNav to open and close affter pressing a button. However, I can only get it to close. When I pass the sideNave() function to button.addEventListener("click", ... ) nothing happens. I would appriciate your help a lot! My code bellow:

const left = document.querySelector("left");
const right = document.querySelector("right");
const button = document.querySelector("button");
button.addEventListener("click", close);
const x = true;

function close() {
  document.getElementById("left").style.width = "0";
  document.getElementById("right").style.width = "100%";
  x = false;
}

function open() {
  document.getElementById("left").style.width = "15%";
  document.getElementById("right").style.width = "85%";
  x = true;
}

function sideNav() {
  if (x = true) {
    w3_close();
  } else {
    open();
  }

}
<!DOCTYPE html>
<html>

<head>
  <title>WebPage</title>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="webPage.css">
  <meta charset="utf-8">
  <script src="https://kit.fontawesome.com/62ea397d3a.js" crossorigin="annonymous"></script>
</head>

<body>
  <div class="header"></div>
  <div id="left">
    <button class="button">Click Me!</button>
  </div>

  <div id="right">
    <p></p>
  </div>
</body>

</html>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Click on the ☰ symbol to open the sidebar (overlays some of the page content). function w3_open () { document.getElementById("mySidebar").style.display = "block"; } function w3_close () {

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