JS: Check If Element With Class Exists

In some cases we add may need to interact with an element with a set class but don’t want to load that code or want to run different code if that element doesn’t exist.

if ($(".mydivclass")[0]) { 
    // Do something if class exists 
} else { 
    // Do something if class does not exist 
}

Powered by BetterDocs