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

214
Vistas
How to show a message when no results are found

How would I adapt this code to show a <div>No Results Found</div> on the page when no results are found?

I've got this simple image gallery with an input to filter results based on the contents of the data-filter attribute:

<input type="text" name="filter" placeholder="Filter" id="filter">
<div class="results-gallery">
    <div class="gallery-thumbnail" data-filter="Apple">image</div>
    <div class="gallery-thumbnail" data-filter="Orange">image</div>
    <div class="gallery-thumbnail" data-filter="Banana">image</div>
</div>

And the jQuery:

$("#filter").keyup(function() {
    var value = $(this).val().toLowerCase();
    $(".gallery-thumbnail").filter(function() {
        $(this).toggle($(this).attr("data-filter").toLowerCase().indexOf(value) > -1);
    });
});
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You could use the same method and do it like this:

$(document).ready( function(){
    $("#filter").keyup( function(){
        var value = $(this).val().toLowerCase();
        $(".gallery-thumbnail").filter(function() {
            $(this).toggle($(this).attr("data-filter").toLowerCase().indexOf(value) > -1);
        });
        $('.noresult').toggle($(".gallery-thumbnail:visible").length == 0)
    });
});

Demo

$(document).ready( function(){
    $("#filter").keyup( function(){
        var value = $(this).val().toLowerCase();
        $(".gallery-thumbnail").filter(function() {
            $(this).toggle($(this).attr("data-filter").toLowerCase().indexOf(value) > -1);
        });
        $('.noresult').toggle($(".gallery-thumbnail:visible").length == 0)
    });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" name="filter" placeholder="Filter" id="filter">
<div class="results-gallery">
    <div class="gallery-thumbnail" data-filter="Apple">image</div>
    <div class="gallery-thumbnail" data-filter="Orange">image</div>
    <div class="gallery-thumbnail" data-filter="Banana">image</div>
    <div class="noresult" style="display:none">No Results Found</div>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You put 'No Results' div on the page, with a class which initially defaults it to be hidden (display:none). If your filter returns no results, you add a class to the div to show it (display: block). When the filter is cleared, and you have results again, you remove the 'show' class, reverting it back to it's default 'hidden' state.

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