Uutiset:

Wondering if this will always be free?  See why free is better.

Main Menu
Advertisement:

SMF and "Filtering with Jquery"

Aloittaja havok4615, lokakuu 10, 2013, 12:56:21 IP

« edellinen - seuraava »

havok4615

Hello, i want to filter a big bunch of information:
im using this code, but the problem is, if i check Category A and B it show, A,B, and AB but i want the Programm only too show Categroy AB, like "Check classes, only show div with exact classes"
Can you guys help me?


<ul id="filters">
    <li>
        <input type="checkbox" value="categorya" id="filter-categorya" />
        <label for="filter-categorya">Category A</label>
    </li>
    <li>
        <input type="checkbox" value="categoryb" id="filter-categoryb" />
        <label for="filter-categoryb">Category B</label>
    </li>
</ul>

<div class="categorya categoryb">A, B</div>
<div class="categorya">A</div>
<div class="categorya">A</div>
<div class="categorya">A</div>
<div class="categoryb">B</div>
<div class="categoryb">B</div>
<div class="categoryb">B</div>
JavaScript:

$("#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.attr("class")) ? "show" : "hide"]();
   });
});

SoLoGHoST

#1
It is not clear what you want exactly...  Do you not want to show A, B when A is only selected or when B is only selected?  Or are you asking to show A, B (only) when both are selected and to show A, B when either are selected, along with all others related to that?  Or... are you asking to not show "A, B" at all, and only show "A"s and/or "B"s?  You really need to be more specific here!

Does this do what you want:  http://jsfiddle.net/mk4PR/

It shows only A, B when A and B are selected, but also shows A, B when either A or B is selected.  If this is not what you want, please be more specific.

Bytheway, this topic really doesn't have anything to do with SMF.

Advertisement: