How do I test if an element with a certain ID exists on a page in jQuery?
<p>In jQuery, I have written a piece of code that appears on every page of my website.</p>

<pre><code>var d = $('#someElement').offset().top;
</code></pre>

<p>However, not every page on my website has an element with an ID of "someElement". Unfortunately, on these pages that lack such an element, no jQuery code works.</p>

<p>To solve this problem, I want to test if an element on the page indeed has the ID of "someElement" and then only run the code snippet above if there is.</p>

<p>How do I perform this test? Will this test solve the problem? Thank you.</p>
