In jQuery, I wrote a piece of code that appears on every page of my site.
var d = $('#someElement').offset().top;
However, not every page of my site has an element with the identifier "someElement". Unfortunately, jQuery code does not work on these pages that lack such an element.
To solve this problem, I want to check if the element on the page really has the identifier "someElement", and then only runs the code snippet, if any.
How to run this test? Will this test solve the problem? Thanks.
source share