Answers for "jquery check if class exists in body"

CSS
1

jquery if class exists

// given an element: <div id="myID" class="wrapper active"> 
//JQuery answer
	if ( $("#myID").hasClass("active") ){
      	//true: myID has class active
      } else {
      	//false: myID does not have class active
      }
Posted by: Guest on May-17-2022
2

if a class exists jquery

if ($(".mydivclass").length){
    // Do something if class exists
} else {
    // Do something if class does not exist
}
Posted by: Guest on November-28-2020
1

jquery check if class exists

// if class exist the expresion will return true and the code from if statement will execute
if ($(".mydivclass")){
    // Do something if class exists
} else {
    // Do something if class does not exist
}
Posted by: Guest on April-23-2022
2

jquery check if a class exists

if ($(".mydivclass")[0]){
    // Do something if class exists
} else {
    // Do something if class does not exist
}
Posted by: Guest on May-06-2020

Code answers related to "jquery check if class exists in body"

Browse Popular Code Answers by Language