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

303
Visualizações
Trying to hide a button element based on a string query in the URL using javascript or JQuery. The URL has a "&" and two "=" to split

Trying to hide a button element based on a string query in the URL using javascript or JQuery

If I have a URL... for ex:

https://xxxxxx.com/xxxxxx.aspx?UserID=12345&type=ABCDE=true

The button:

 <button class="smallButton"> </button> 

How do I hide the button if ABCDE= true and show if it's not? I read other posts but they didn't seem to work. Because of the "&" and the two "=" in the string, it's a little different than the example's I've seen. Any help is appreciated. Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can get the query string params by using URLSearchParams with .get

Then to get only it's value trim the string before the = and just show or hide the button based on the condition.

You can do it like this:

let searchParams = new URLSearchParams("https://xxxxxx.com/xxxxxx.aspx?UserID=12345&type=ABCDE=true")
// let searchParams = new URLSearchParams(window.location.search) uncomment if you want to use your current window location URL.

if (searchParams.has('type')) { // check if the type exist in query string
  let param = searchParams.get('type') // get the param
  param = param.substr(param.indexOf('=') + 1, param.length) // trim the value to get true from "ABCDE=true" so in substr you're going to get the string from the char = position + 1 to the end of the string.

  if (param == 'true') { // check if the param is true
    $('.smallButton').show(); // show the button
  } else { 
    $('.smallButton').hide(); // hide it
  }
}
.smallButton {
  display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="smallButton">
SMALL BUTTON
</button>

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