how to check has class in jquery code example
Example 1: jquery hasclass
if ($( "#foo" ).hasClass('className')) {
$( "#foo" ).removeClass( 'className');
} else {
$( "#foo" ).addClass( 'className');
}
Example 2: javascript check if element has class
if(document.getElementById("myElmentID").classList.contains("hidden")){
}
Example 3: jquery hasclass
$( "#mydiv" ).hasClass( "foo" )
Example 4: jquery hasclass
jQuery(Selector).hasClass('class_name');
Example 5: has class in jquery
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>hasClass demo</title>
<style>
p {
margin: 8px;
font-size: 16px;
}
.selected {
color: red;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<p>This paragraph is black and is the first paragraph.</p>
<p class="selected">This paragraph is red and is the second paragraph.</p>
<div id="result1">First paragraph has selected class: </div>
<div id="result2">Second paragraph has selected class: </div>
<div id="result3">At least one paragraph has selected class: </div>
<script>
$( "#result1" ).append( $( "p" ).first().hasClass( "selected" ).toString() );
$( "#result2" ).append( $( "p" ).last().hasClass( "selected" ).toString() );
$( "#result3" ).append( $( "p" ).hasClass( "selected" ).toString() ) ;
</script>
</body>
</html>
Example 6: button has class or not c#
if(el.getAttribute("class").split(" ").contains("disabled"))
{
}
or
#region HTML Method
public static bool hasClass(WebControl element, string strClass)
{
return Convert.ToString(element.Attributes["class"]).Split(' ').Contains(strClass);
}
#endregion