To check the length of the selector, if it returns you something then the element exists else not exist.
Use:
1 2 3 4 5 6 7 8 9 10 11 12 | $( '#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?