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

760
Visualizações
show and hide button in php

I'm working on side php project and I'm just wondering how can I modify my code so that there will be only one button instead of two.

Right now, I have show and hide buttons. I'm thinking about having only one button and it will display Hide option first. after a user click Hide option then it'll change it to show.

<button type="button" class="btn btn-light" onClick="hide_div('transpose-keys');">Hide</button>
<button type="button" class="btn btn-light" onClick="show_div('transpose-keys');">Show</button>
function hide_div(e) {
  $(".c").hide()
  $("."+e).hide()
}
function show_div(e) {
  $(".c").show()
  $("."+e).show()
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. You need to define a CSS class to hide elements, { display: none }.
  2. That class will be injected to the target element to hide it or removed to get it back to be displayed.

setHiddable("hide-show", "target");

/**
 * Ideal to set a hide/show relationship between only two elements
 * @param {string} btnId The ID of the button that toggle the view
 * @param {string} elementId The ID of the element to be toggled
 */
function setHiddable(btnId, elementId) {
    const btn = document.querySelector(`#${btnId}`);

    // Listen to clicks
    btn.addEventListener("click", (ev) => {
        const targetEl = document.querySelector(`#${elementId}`);
        // Hide if shown
        // Show if hidden
        targetEl.classList.toggle("hidden");
    });
}
#target {
  height: 100px;
  width: 100px;
  background: red;
}

.hidden{
  display: none;
}
<div id="target"> This is the element that you want to show and hide on click </div>

<button type="button" class="btn btn-light" id="hide-show">TOGGLE VIEW</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