Jquery multiple selectors, select items which match both criteria

css-selectors, jquery

Solution

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();

Problem

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.

Original source