Note that there are some explanatory texts on larger screens.

plurals
  1. POMatching elements by class to an array and displaying only elements that match all array values
    primarykey
    data
    text
    <p>I have the function below that was originally designed to check multiple checkboxes to see if they were checked and then show any <code>&lt;p id="com"&gt;</code> with classes that matched those of the "checked" checkboxes. As you can see this function is run on each click of a checkbox.</p> <pre><code>function Checked() { var classes = []; $('input:checked').each(function(){ classes.push($(this).attr('class')); }); $('p#com').hide(); for ( var i = 0; i &lt; classes.length; i++ ) { if ($('p#com').hasClass(classes[i])){ $('p.'+classes[i]).show(); } } } Checked(); $(':checkbox').click(Checked); </code></pre> <p>The criteria has now changed ands there are more categories of options required. What I now have is 4 groups of radio buttons. So a maximum of 4 possible checked values, but I would like to show only <code>&lt;p id="com"&gt;</code> that have classes that match all the array values only. For example</p> <p>Radio 1 - defines type</p> <p>Radio 2 - defines finish</p> <p>I would like to adapt the function to show ONLY classes that match type and finish, not BOTH type and finish separately as it currently does. I am basically stuck and not sure where to go from here, any help would be much appreciated.</p> <p>The new html would look like this.</p> <pre><code>&lt;div&gt; Type&lt;br /&gt; &lt;input type="radio" name="type" class="manual" /&gt;Manual&lt;br /&gt; &lt;input type="radio" name="type" class="modern" /&gt;Modern&lt;br /&gt; &lt;input type="radio" name="type" class="thermo" /&gt;Thermostatic&lt;br /&gt; &lt;input type="radio" name="type" class="trad" /&gt;Traditional &lt;/div&gt; &lt;div&gt; Finish&lt;br /&gt; &lt;input type="radio" name="finish" class="chrome" /&gt;Chrome&lt;br /&gt; &lt;input type="radio" name="finish" class="antbrass" /&gt;Antique Brass&lt;br /&gt; &lt;input type="radio" name="finish" class="golbra" /&gt;Brass - Gold &lt;/div&gt; &lt;p class="antbrass manual trad" id="com"&gt;Content&lt;/p&gt; &lt;p class="manual modern chrome" id="com"&gt;Content&lt;/p&gt; &lt;p class="antbrass manual trad" id="com"&gt;Content&lt;/p&gt; &lt;p class="manual modern chrome" id="com"&gt;Content&lt;/p&gt; </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