This snippet shows how to check if jQuery selector exists.
Source code viewerif ($(selector).length) { // if selector exists do these things} if (!$(selector).length) { // if selector does not exist do these things}Programming Language: jQuery