Jquery - alternative to .length to check if element exists
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery">Is there an &ldquo;exists&rdquo; function for jQuery</a>  </p>
</blockquote>



<p>Just as the title suggests, whats the best way to check if an element exists with jquery.  I find myself constantly using .length on elements.</p>

<p>Is there a better way of doing this?</p>

<p>The way i typically use it is that if i am going to do anything with an element in a script ill check if the element exists on that page or not.  This is ending up in a lots of blocks of code wrapped in if($('el').length) {</p>
