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

228
Vistas
Javascript Conditional Statement Based on Cookie Value

I'm using cookies to scroll to different sections of a given page. The cookies are saved fine. Only one cookie can exist at a given time. I can see them in the application as they should be. However, there is an issue with my conditionals where only the last if statement runs.

jQuery(document).ready(function ($) {
 
  var internetcsomagcookie = null;
  var csomagcookie = "true";
  var triocsomagcookie = null;
  var tvcsomagcookie = null;


  if ((csomagcookie = "true")) {
      document.getElementById("csomag").scrollIntoView();
  }

  if ((triocsomagcookie = "true")) {
      document.getElementById("trio").scrollIntoView();
  }

  if ((internetcsomagcookie = "true")) {                                 document.getElementById("internet").scrollIntoView();
    
  }

  if ((tvcsomagcookie = "true")) {

      document.getElementById("tv").scrollIntoView();
    
  }
});
#internet,#trio,#tv,#csomag {height:1000px;}


#internet {background:blue;}

#tv {background:red;}

#csomag {background:green;}

#trio {background:orange;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="csomag"></div>

<div id="trio"></div>

<div id="internet"></div>

<div id="tv"></div>

The issue is, that after creating any of the cookies (except for the last one - tvcsomagcookie), whenever I load the page where I want the scrolltoview to happen on, it jumps to the last ID in the code (basically the last if statement executes that scrolls to #tv), despite the tvcsomagcookie returning 'null'. So it runs when it should not.

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

0

If statements were originally posted with = (which is for assignment) instead of == for comparison. Updating this inside the code fixed the issue.

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