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

124
Vistas
How to restore div which is hidden using empty() function

html code:
<button id="add"></button>    
<div id="count_search">
        <span class="total_count">Total: <span id="record_count"></span></span></span>
        <input type="text" class="txtbox search" placeholder="Search" id="search">
    </div>
Jquery code:
$("#add").click(function(){
       $("#count_search").empty();
})

I want to show count_search div once again on clicking on any other button execpt to add button In above code add is button on which empty() is implimented. On clicking on add button count_search is got hide. Then after I want to restore that div content

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

0

.empty() deletes the elements in your container (count_search). Instead, you can use .hide()/.show() or better approach, you can use .toggle() that show or hide your element.

$("#add2").click(function() {
    $("#count_search").toggle();
});
$("#add").click(function() {

    if ($("#count_search").is(":visible")) {
        $("#count_search").hide();
    } else {
        $("#count_search").show();
    }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="add">Show/Hide</button>    
<button id="add2">Toggle</button>    
<div id="count_search">
   <span class="total_count">Total: <span id="record_count"></span></span></span>
   <input type="text" class="txtbox search" placeholder="Search" id="search">
</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

By empty() you are deleting an item in DOM.
Instead of empty, you can use toggle(), which hides the element and If you click once again, the item will show.

$("#add").click(function(){
       $("#count_search").hide();
})
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