Note that there are some explanatory texts on larger screens.

plurals
  1. POcomplex filter in jquery
    primarykey
    data
    text
    <p>I have a list of products I am displaying and I am currently working on a filtering function that does not use ajax.</p> <p>Every product has a series of classes attached to it based on a category it falls under. So like this:</p> <pre><code>&lt;li class="f_all f_cat1 f_cat2"&gt;Product 1&lt;/li&gt; &lt;li class="f_all f_cat1 f_cat3 f_cat_4"&gt;Product 2&lt;/li&gt; &lt;li class="f_all f_cat4 f_cat5 f_cat6"&gt;Product 3&lt;/li&gt; </code></pre> <p>This means that many products fall under the same category.</p> <p>These are the filter options:</p> <pre><code>&lt;table cellspacing="10"&gt; &lt;tr&gt; &lt;td class="item" id="p_1"&gt;Category 1&lt;/td&gt; &lt;td class="item" id="p_2"&gt;Category 2&lt;/td&gt; &lt;td class="item" id="p_3"&gt;Category 3&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>I have a basic filter working so far, that allows me to filter based on a single category, that looks like this:</p> <pre><code>function filterProd(filter){ $(".f_all").hide(); // first hide all products $(".f_"+filter).show(); // show products only for this category } </code></pre> <p>Then the click function:</p> <pre><code>$("#p_1").click(function(){filterProd("cat1");}); $("#p_2").click(function(){filterProd("cat2");}); $("#p_3").click(function(){filterProd("cat3");}); </code></pre> <p>I know that this is not the ideal way to do this but i'm just looking for a little guidance.</p> <p>I am trying to achieve 2 things after this:</p> <p><li>When the option is clicked AGAIN, remove that filter from the function</li> <li>When another option is clicked, ADD it to the filter</li></p> <p>I am assuming a function of sorts that accepts an array of values etc, but i'm fairly new to jquery and would appreciate any help i can get at this point.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload