RSSArchive for January, 2013

Jan

23

Check if Element Exists Using Javascript or jQuery

Posted by Leave a Comment

To check if an element exists on a page you can use the getElementById method:

if (document.getElementById('theID')) { }

You can also do this by using jQuery’s length method:

if ($('#theID').length) { }