Check if element exists with javascript

Use this code snippet to check by id if an element exists in your document:

if(document.getElementById('id_of_element'))
{
    alert('element exists!');
}

You can achieve a similiar result using jQuery:

if ($('#id_of_element').length > 0)
{
    alert('element exists!');
}

Sign Up
comments powered by Disqus
Sign Up

Popular Tags

350x250

Need a web developer?

If you'd like to work with code synthesis on your next project get in touch via the contact page.