views:

3265

answers:

1

if i do this...

$('.class1, .class2').hide();

Then all items with class1 or with class2 will be hidden.

<pre class='class1'>hello1</pre>
<pre class='class2'>hello2</pre>
<pre class='class1 class2'>hello3</pre>

What is the syntax so only the 3rd <pre> will be hidden, I want to hide things based if they have both class1 and class2.

+6  A: 

The same as the CSS selectors for it - class identifiers with no spaces in between:

$('.class1.class2').hide();

jQuery documentation here: .class.class selectors.

Although if these classes are only going to be on <pre> elements, this is best:

$('pre.class1.class2').hide();
Paolo Bergantino
Thanks for the very quick reply, thats exactly what i needed. Thanks.
Notice that syntax works to combine other sorts of jquery things, e.g. $(':input:visible') finds visible input tags.
dfrankow