mercredi 20 juillet 2016

jquery show div only if no results returned in search

I have the following code that I need some guidance with please. I need the #no-results element to appear only if no results are found. Currently it shows IF results are found.

 $('#no-results').hide();
        $('#video-search-text').keyup(function () {
            $('.video-search').hide();
            $('#no-results').css("display", "none");
            var txt = $('#video-search-text').val(); 

            $('.video-search').each(function () {
                if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
                    $(this).show(); 

                }
                else {
                      $('#no-results').css("display", "block");

                }
            });

        });

I have created the following JSFiddle for convenience. Thanks

Aucun commentaire:

Enregistrer un commentaire