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 }
What do you think?