Note that there are some explanatory texts on larger screens.

plurals
  1. POAdvanced filtering with jQuery, need direction on best way
    text
    copied!<p>I need advice on the best way to go about doing some filtering in jQuery.</p> <p><strong>HTML</strong></p> <p>I have a form that contains an unorderd list of attributes:</p> <pre><code>&lt;form name="attrList"&gt; &lt;ul&gt; &lt;li&gt; &lt;input type="checkbox" name="FILTER" value="1+" /&gt; 1+ &lt;/li&gt; &lt;li&gt; &lt;input type="checkbox" name="FILTER" value="Adrian Chesterman" /&gt; Adrian Chesterman &lt;/li&gt; &lt;li&gt; &lt;input type="checkbox" name="FILTER" value="Green" /&gt; Green &lt;/li&gt; &lt;/ul&gt; &lt;/form&gt; </code></pre> <p>Then I have a set of divs. I gave the div an attribute of "attrList", like so:</p> <pre><code>&lt;div class="productContainer" attrList="1+,Andy Thomas"&gt; &lt;h3&gt;Some Name Here&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;1+&lt;/li&gt; &lt;li&gt;Andy Thomas&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p><strong>jQuery</strong></p> <ol> <li>When a any input[name=FILTER] is clicked, I'm building a list of all input[name=FILTER]:checked. </li> <li>I'm looping through all divs</li> <li>During the loop, I'm checking the attrList attribute (e.g. attrList="red") on that div to see if what was clicked is found in that list. </li> <li>If it isn't found I'm moving the div out of sight into a different div</li> </ol> <p><strong>JSBin Example</strong></p> <p>The example above has been simplified so you could see the basics of what I was doing. <a href="http://jsbin.com/upeki3/8" rel="nofollow">JSBin Link Here</a></p> <p><strong>Need Your Advice</strong></p> <p>This is the first time I've gone about doing this kind of filtering; I'm just looking for a best practice from someone who has been here before. I'd really appreciate your feedback!</p>
 

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