Note that there are some explanatory texts on larger screens.

plurals
  1. POfiltering data with check boxes using jquery
    primarykey
    data
    text
    <p>I am attempting to filter div items depending on whether certain check boxes are checked or not, by default all will be checked.</p> <p>I have managed to get the filtering to work but I am struggling to append an error message if no results found (if no check box is checked)</p> <blockquote> <p><strong>No results found, Please reset filter and search again</strong></p> </blockquote> <p>I have placed my code here <a href="http://jsfiddle.net/3WcDC/25/" rel="nofollow">http://jsfiddle.net/3WcDC/25/</a></p> <p>Thank you in advanced to anyone who can help me, it's much appreciated.</p> <h3>HTML</h3> <pre><code>&lt;div id="CategoryContent"&gt; &lt;div class="product"&gt;Brand1&lt;/div&gt; &lt;div class="product"&gt;Brand2&lt;/div&gt; &lt;div class="product"&gt;Brand3&lt;/div&gt; &lt;div class="product"&gt;Brand4&lt;/div&gt; &lt;h2&gt;Brands:&lt;/h2&gt; &lt;input type="checkbox" name="brand" value="Brand1"/&gt;Brand1 &lt;/br&gt; &lt;input type="checkbox" name="brand" value="Brand2"/&gt;Brand2 &lt;/br&gt; &lt;input type="checkbox" name="brand" value="Brand3"/&gt;Brand3 &lt;/br&gt; &lt;input type="checkbox" name="brand" value="Brand4"/&gt;Brand4 &lt;/br&gt; &lt;/div&gt; </code></pre> <h3>The javascript for filtering:</h3> <pre><code>var $filters = $("input:checkbox[name='brand']").prop('checked', true); // start all checked var $categoryContent = $('#CategoryContent div'); $filters.click(function() { // if any of the checkboxes for brand are checked, you want to show div's containing their value, and you want to hide all the rest. $categoryContent.hide(); $filters.filter(':checked').each(function(i, el) { $categoryContent.filter(':contains(' + el.value + ')').show(); }); }); </code></pre>
    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.
    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