Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It would be helpful if you had included some HTML, but since you didn't I'm going to assume that you have something that looks like this:</p> <p><strong>HTML</strong></p> <pre><code>&lt;fieldset&gt; &lt;label&gt;&lt;input type="radio" name="type" value="active" /&gt;Active&lt;/label&gt; &lt;label&gt;&lt;input type="radio" name="type" value="alternative" /&gt;Alternative&lt;/label&gt; &lt;label&gt;&lt;input type="radio" name="type" value="classic" /&gt;Classic&lt;/label&gt; &lt;label&gt;&lt;input type="radio" name="type" value="vintage" /&gt;Vintage&lt;/label&gt; &lt;/fieldset&gt; &lt;div id="result"&gt;You picked: &lt;span id="selection"&gt;&lt;span&gt;&lt;/div&gt; &lt;div class="products"&gt; &lt;div class="vintage classic"&gt;Vintage and Classic&lt;/div&gt; &lt;div class="vintage"&gt;Vintage&lt;/div&gt; &lt;div class="classic"&gt;Classic&lt;/div&gt; &lt;div class="classic alternative"&gt;Alternative and Classic&lt;/div&gt; &lt;div class="alternative"&gt;Vintage and Classic&lt;/div&gt; &lt;/div&gt; </code></pre> <p>The solution is simple and you don't even need a conditional. The way I would accomplish it is with the following JavaScript:</p> <p><strong>JavaScript</strong></p> <pre><code>$("input[name='type']") .on("click", function() { // Clear result showing state $("#result").removeAttr("class"); // Get selected value var typeVal = $(this).attr("value"); $("#result").addClass(typeVal); $("#selection").text(typeVal); // Remove match class $(".products div").removeClass("match"); // Show matching products and add match class $(".products ." + typeVal).addClass("match"); }); </code></pre> <p>With this CSS:</p> <p><strong>CSS</strong></p> <pre><code>.active { color: #f00; } .alternative { color: #0f0; } .classic { color: #00f; } .vintage { color: #999; } .match { background: #ccc; } </code></pre> <p>Here's a link to the jsFiddle: <a href="http://jsfiddle.net/XQVet/3/" rel="nofollow">http://jsfiddle.net/XQVet/3/</a></p> <p><strong>Update:</strong> Changed it so that elements wouldn't disappear.</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.
    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