Check if a DIV exist before running some Javascript
<p>I am having a problem, on a blog I have this javascript code below that is used to get the Position of a DIV id <code>author-info</code>.  The problem is this div is only on actual article pages and not on any of the directory pages or the index.</p>

<p>So on these pages that do not have the div I get this error</p>

<pre><code>Uncaught TypeError: Cannot read property 'top' of null
</code></pre>

<p>And here is the javascript causing the error</p>

<pre><code>var commentsPos = $('#author-info').offset().top - $(window).height();
</code></pre>

<p>I know I could do this in the backend to only show that line of JS on the proper pages but I would like to avoid that as this is just 1 line of a much bigger javascript file that is included into the page.  </p>

<p>What are my options here?  Any help please, I assume I need to somehow check to see if this div exist on the page before calling this action?</p>
