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

177
Visualizações
Trying to get search bar to display when you click button?

What I am trying to do is, that when the user clicks on the search button, the search bar displays. But for some reason, it's just not working and I have no idea, why? I double-checked on https://www.w3schools.com/jsref/event_onclick.asp just to make sure I am doing it right but to no avail. I tried the add.eventlistner that does not work, because it sees the button as null where the onclick="showBar()" should see the button, in JS.

HTML

<button onclick="showBar()" class="btn btn-outline-success" type="submit">
  Search
  <img src="./images/iconmonstr-search-thin-240.png" alt="search icon">
</button>

CSS

.form-control, .me-2 {
  animation: slide 1s 1;
}

.me-2 {
  display: none !important;
}

JS

let slideSearch = document.querySelector(".me-2");

function showBar() {
  slideSearch.style.display = "block";
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your problem is you're using !important on display: none of .me-2.

You should not use !important in your style unless you want to hide it permanently.

let slideSearch = document.querySelector(".me-2");

function showBar() {
  slideSearch.style.display = "block";
}
.form-control, .me-2 {
  animation: slide 1s 1;
}

.me-2 {
  display: none; /*Removed !important*/
}
<button onclick="showBar()" class="btn btn-outline-success" type="submit">
  Search
  <img src="./images/iconmonstr-search-thin-240.png" alt="search icon">
</button>
<input class="me-2"/>

If you cannot get rid of !important for some reason. You can try to add !important to .me-2 in Javascript that would override !important in your CSS.

let slideSearch = document.querySelector(".me-2");

function showBar() {
  slideSearch.style.setProperty('display','block','important');
}
.form-control, .me-2 {
  animation: slide 1s 1;
}

.me-2 {
  display: none !important;
}
<button onclick="showBar()" class="btn btn-outline-success" type="submit">
  Search
  <img src="./images/iconmonstr-search-thin-240.png" alt="search icon">
</button>
<input class="me-2"/>

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