JQuery optimization for searching classes <p>I have some filters on the left. Each filter has an id. The id of that filter is used to filter some results that have the id of the filter in their classes.</p> <p>Filters refer to characteristics of products.. example</p> <pre><code>&lt;a id="filter_colorRED"&gt;RED&lt;/a&gt; ... &lt;li id="item4" class="filter_colorBLUE"&gt;Blah Blah&lt;/li&gt; &lt;li id="item5" class="filter_colorRED "&gt;Blah Blah&lt;/li&gt; &lt;li id="item6" class="filter_colorRED filter_colorBLACK"&gt;Blah Blah&lt;/li&gt; </code></pre> <p>I am looking for the best method to find which filters should be disabled. Disabled filters should be these that dont exist in visible items' classes.</p> <p>For example if colorBlue is applied RED and BLACK should be disabled because the only <code>&lt;li&gt;</code> that has the BLUE class doesn't contain RED or BLACK.</p> <p>My only thought is for each filter to check against results <code>.hasclass(filter's id)</code> but I think that this is poor. Any other idea?</p>