How to include a script tag only if an element exists?
<p>This seems like something that should be straightforward but I'm a newbie with Javascript, so please be patient.</p>

<p>I want to include a script file but only if an element exists on the page.  I've tried:</p>

<pre><code>var element = $('.customelement');

if(element.length() &gt; 0) {
  $('head').append('&lt;script language="javascript" src="custom.js"&gt;&lt;/script&gt;');
}
</code></pre>

<p>But this doesn't work and returns the error:</p>

<blockquote>
  <p>Uncaught TypeError: Property 'length' of object [object Object] is
  not a function</p>
</blockquote>

<p>I have found many posts which say this should work so I'm a little stumped.  I was also wondering if there is a better way to do this?</p>
