jQuery Filter children which has a particular attribute
<p>I have some <code>li</code> elements among them some of the <code>li</code> has an attribute <code>data-brandId</code> and some of them don't have this attribute. I have the parent <code>ul</code> from which I am filtering it as:</p>

<pre><code>var selectedLis = new Array();
$('ul').children('li').each(function(){
    if($(this).attr(attribute) != null) {
        selectedLis.push($(this));
    }
});
</code></pre>

<p>Is there any better way to achieve this; like by using <code>filter</code> etc?</p>

<h2>Update:</h2>

<p>I am getting <code>TypeError: $(...).data(...) is undefined</code></p>

<p>The rendered HTML is:</p>

<pre><code>&lt;li data-entityid="WF/008/DAM" class="dropdownli filterItem"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
    &lt;input type="checkbox" data-entityid="WF/008/DAM" value="WF/008/DAM/014" name="damBrand"&gt;
    &lt;label&gt;E&amp;amp;W Portfolio&lt;/label&gt;
&lt;/li&gt;
</code></pre>

<p>This is giving me the error:</p>

<pre><code>var lis = $('ul[name=damBrandMenu]').children('li').filter(function(){
    return $(this).data('entityId').length;
});
</code></pre>

<p>Also say I don't have the data-entityId in the <code>li</code>, instead I have this attribute in the input[type="checkbox"] which is the child of li, as you can see in the HTML. Then what will be the way for filtering? Is it:</p>

<pre><code>var lis = $('ul[name=damBrandMenu]').children('li').filter(function(){
    return $('&gt; input[type="checkbox"]', this).data('entityid').length;
});
</code></pre>

<p>I have also tried: <code>$(this).attr('data-entityId').length;</code> and <code>$('&gt; input[type="checkbox"]', this).attr('data-entityId').length;</code>, but they are also not working. I am having same error; <code>TypeError: $(...).attr(...) is undefined</code>.</p>
