jquery check if a class exists
snippet in javascript

jquery check if a class exists

user5620

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

if a class exists jquery

user8220

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