Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda