jQuery check if element exist

To check the length of the selector, if it returns you something then the element exists else not exist.

Use:

$('#element_id').length

if( $('#selector').length )         // use this if you are using id to check
{
     // it exists
}


if( $('.selector').length )         // use this if you are using class to check
{
     // it exists
}

By Keenlio, March 17, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *


7 + three =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>