Check if an element exists in the DOM
<p>The following snippet is not working for me. Basically I want to check if there is an input element with the name "documents[]" and the value item.id and return void.</p>

<p>I thought this line would do it: <code>$("input [name='documents[]'][value='"+item.id+"'") != false</code>. </p>

<p>However the statement returns true every time. I have looked at the documentation for the jQuery constructor and it doesn't mention anything about returning false if no element is found for the selector. </p>

<p>How can I tell if the selector doesn't match any elements?</p>

<pre><code>    $.ajax({
        url:'/myid/documents/json_get_documents/'+request.term,
        dataType:"json",
        success: function(data) {
            response($.map(data, function(item){
                if($("input [name='documents[]'][value='"+item.id+"'") != false) {
                    return; //This item has already been added, don't show in autocompete
                }
                return {
                    label: '&lt;span class="file"&gt;'+item.title+'&lt;/span&gt;',
                    id: item.id,
                    value: 'Search by title'
                }
            }))
        }
    });
</code></pre>
