I'm trying to hide all items tagged with a specific class upon
clicking on a span with a similar tag.

                $("#tags span").click(function(){
                var whichClass = $(this).attr("class");
                //hide all the p's that do not match the class clicked
                $("p[class!='"+whichClass+"']").hide();
                //show any straggling, hidden p's with the right class
                $("p[class='"+whichClass+"']").show();});

<div id="tags">
<span class="first">First</span>
<span class="second">Second</span>
</div>

<div>
<p class="first">Some text</p>
<p class="second">Some more text</p>
<p class="first second">Even more text</p>
</div>

Clicking first shows the first p, and hides the rest. Clicking second
shows the second p, and hides the rest. However, each, upon clicking,
should not hide the third p. It seems that $("p[class!='"+whichClass
+"']") matches exactly, rather than matching by mere containing.

Any suggestions for how to have the jquery recognize multiple classes?

Thanks

Reply via email to