How to properly do JS condition?
<p>I run this jQuery (1.8.3) code and always get the "in" alerted even when the length is greater than 1.</p>

<p>What I'm doing is dynamically adding elements to a menu and the if is to make sure this element doesn't exist yet.</p>

<p>I tried also <code>== 0</code> and <code>=== 0</code> but the result is the same...</p>

<p>Here is a JS fiddle: <a href="http://jsfiddle.net/mHhwq/4/" rel="nofollow">http://jsfiddle.net/mHhwq/4/</a></p>

<pre><code>$(".sidebarit a.olink").click(function(event){
   iframe_url = $(this).attr("href");
   sidebar_id = '#' + iframe_url.replace(/[/.]/g, '');
   alert('sidebar_id: ' + sidebar_id);

   // create the sidebar if it doesn't exist
   if ($(sidebar_id).length &lt; 1) {
      alert("in");
      $("#sidebar_nav ul").append('&lt;li&gt;&lt;/li&gt;');
      $("#sidebar_content").append('&lt;div id="' + sidebar_id + '" style="display:none;"&gt;&lt;/div&gt;&lt;/div&gt;');
   } else { alert("out"); }

   // don't follow the link
   event.preventDefault();
});
</code></pre>

<p>In FireBug I see the length equals 1 but still enters the block.</p>

<p>What am I doing wrong?</p>

<p><strong>Update:</strong></p>

<p>My mistake was that I added the <code>#</code> at the wrong place...</p>
