// 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
}
if ($(".mydivclass").length){
// Do something if class exists
} else {
// Do something if class does not exist
}
$("#EL_ID").hasClass("CLASS_NAME");
if ($(".mydivclass")[0]){
// Do something if class exists
} else {
// Do something if class does not exist
}
if ($("#about").hasClass("opened")) {
$("#about").animate({right: "-700px"}, 2000);
}
// 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
}
/* Answer to: "jquery check if element has class starting with" */
if(!$(this).is('[class*="answerbox"]')) {
//Finds element with no answerbox class
} else {
//The element has already an answerbox class
}
jQuery(function ($) {
if ($(".className").length == 0) {
$(".element").removeAttr("style").hide();
}else{
$(".element").removeAttr("style").show();
}
});
if ($(".mydivclass")[0]){
// Do something if class exists
} else {
// Do something if class does not exist
}
Code Example |
---|
Css :: css change text spacing |
Css :: how to make all buttons same size css |
Css :: green hex code |
Css :: center div inside div flex |
Css :: label width css |
Css :: remve arrow from input ype number |
Css :: text stock css |
Css :: remove hover css on a text |
Css :: ghana |
Css :: need short long paragraph css |
Css :: linux bash sort folders ascending |
Css :: get second child div css |
Css :: how to fix the nav bar to the left of the page |
Css :: ul list style type image |
Css :: center with flex |
Css :: responsive flexbox in css |
Css :: align text in center css |
Css :: css main container align center |
Css :: css selector not contain |
Css :: center a spinner css |
Css :: padding for text in html |
Css :: css text spacing |
Css :: table font size |
Css :: hidden vs visible |
Css :: remove on click border |
Css :: ignore br css |
Css :: css background properties |
Css :: line-height css |
Css :: css align bottom of container |
Css :: transition shorthand |