check if has class code example

Example 1: javascript check if element has class

if(document.getElementById("myElmentID").classList.contains("hidden")){
// I have the 'hidden' class
}

Example 2: check if a class exists javascript

const element = document.querySelector("#box");

element.classList.contains("active");

Example 3: jquery hasclass

jQuery(Selector).hasClass('class_name');

Example 4: how to check has class name in js?

element.classList.contains(className);Code language: CSS (css)

Example 5: button has class or not c#

//How to check if class attribute contains something?
//https://stackoverflow.com/questions/34992613/how-to-check-if-class-attribute-contains-something
//el is the web element
if(el.getAttribute("class").split(" ").contains("disabled"))
{  
    //your code
}

or 

#region HTML Method
public static bool hasClass(WebControl element, string strClass)
{
  return Convert.ToString(element.Attributes["class"]).Split(' ').Contains(strClass);
}
#endregion

Tags:

Css Example