how to select all elements containing at least one [attr=name1] element which, in its turn, contain at least one [attr=name2] element?
<p>I have this markup:</p>

<pre><code>&lt;div class="click"&gt;click&lt;/div&gt;
&lt;div id="wrapper"&gt;
&lt;div class="container"&gt;
&lt;div data-attrfirst='type1'&gt;&lt;span data-attrsecond='type2'&gt;must be red&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>I want to select all the <code>.container</code>s that:<br>
1. are inside of <code>#wrapper</code>;<br>
2. contain <code>data-attrfirst='type1'</code> element which, in its turn, contain <code>data-attrsecond='type2'</code> element.<br>
My requirements:<br>
1. My '#wrapper', 'type1', 'type2' values MUST be kept as variables.<br>
2. I MUST find this all inside of some tag (in this case, I choose <code>body</code>).</p>

<p>I tried this (asterisks may be removed, no difference):</p>

<pre><code>&lt;script&gt;
    $(document).ready(function () {
        $('.click').click(function () {
            var myid = '#wrapper';
            var attrfirst = 'type1';
            var attrsecond = 'type2';
            var elem = $('*[data-attrfirst=' + attrfirst + ']').has('*[data-attrsecond=' + attrsecond + ']');
            $('body').find(myid + ' .container').each(function (i) {
                if ($(this).has('*[data-attrfirst=' + attrfirst + '] *[data-attrsecond=' + attrsecond + ']')) {
                    $(this).css('color', 'red')
                }
            });

            $('body').find(myid + ' .container').each(function (i) {
                if ($(this).has(elem)) {
                    $(this).css('color', 'red')
                }
            });
            $('body').find(myid + ' .container').filter(function (i) {
                return $('*[data-attrfirst=' + attrfirst + '] *[data-attrsecond=' + attrsecond + ']', this).length &gt;= 1
            }).css('color', 'red')
        });
    });
&lt;/script&gt;
</code></pre>

<p>Where am I wrong? And I don't understand from Jquery docs, does <code>.has</code> accept Jquery object? </p>
