mardi 16 avril 2019

Javascript checkbox tag filter: Issue to hide results when unchecked

I have this content filter with checkbox that works getting the .text inside the option.

The issue is that It does not reset after uncheck, and show all the content that suppose to be filtered.

$("#filters :checkbox").click(function() {

   var re = new RegExp($("#filters :checkbox:checked").map(function() {
                          return this.value;
                       }).get().join("|") );
   $("div").each(function() {
      var $this = $(this);
      $this[re.source!="" && re.test($this.text().toLowerCase()) ? "show" : "hide"]();
   });
});

It should clean the results.

The whole code is here in JsFiddle https://jsfiddle.net/4fhkzxdp/1/




Aucun commentaire:

Enregistrer un commentaire