Search code examples
jquerysearchfilternegation

Search Field. How to code: If you cannot find a value


I wrote this JS Code

$("#itemSearch").on("keyup", function () {

  if ($("#itemSearch").val().trim() == '') {
    $(".card-content").show();
  }

  else {
    var value = $(this).val().trim().toLowerCase() ;
      $(".card-group").filter(function () {
      $(this).toggle($(this).text().trim().toLowerCase().indexOf(value) > -1)
    });
  }
});

and want to say something like:

$(".card-group"):not.text()
alert ("1");

or

$(".card-group").text ! value
alert("1");

Can anybody help maybe?

Greetings Erya


Solution

  • I know the answer now. It works with include()!

    $("#itemSearch").on("keyup", function() {
    
    if ($("#itemSearch").val() == '') {
      $(".card-content").show();
      showPage(1);
      $(".pagination").css("display", "flex");
    }
    
    else {
    
    var value = $(this).val().toLowerCase();
    
    $(".card-group").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
    
    $(".pagination").css("display", "none");
    
    **if ($(".card-group").text().toLowerCase().includes(value)) {
      alert ("1");
    }
    else {
      alert ("2");
    }**
    
    }
    
    });