Answered by : code-grepper
if(document.getElementById("myElmentID").classList.contains("hidden")){
// I have the 'hidden' class
}
Source : | Last Update : Fri, 09 Aug 19
Answered by : xanthous-xenomorph-wyygzq6lf3lv
const element = document.querySelector("#box");
element.classList.contains("active");
Source : https://codetogo.io/how-to-check-if-element-has-class-in-javascript/ | Last Update : Sat, 15 Aug 20
Answered by : ivan-londono
if (typeof maybeObject != "undefined") { alert("It exists!");
}
Source : | Last Update : Wed, 25 Jan 23
Answered by : akbarali
var isMobileVersion = document.getElementsByClassName('snake--mobile');
if (isMobileVersion.length > 0) { // elements with class "snake--mobile" exist
}
Source : | Last Update : Wed, 13 Apr 22
Answered by : armando-flores
{"tags":[{"tag":"textarea","content":"expect(elem.contains('foo')).toBe(true); \/\/expect elem to contain class foo\n\/\/ Use above if at least this class is expected to be included.\n\/\/ If an exact series of classes are expected to be in elem use below\nexpect(elem).toHaveClass(\"class1 class2\");","code_language":"javascript"}]}
Source : | Last Update : Tue, 21 Mar 23
Answered by : yann-deo
const div = document.querySelector('.info');
div.classList.contains('secondary'); // trueCode language: JavaScript (javascript)
Source : https://www.javascripttutorial.net/dom/css/check-if-an-element-contains-a-class/ | Last Update : Sat, 19 Jun 21
Answered by : ivan-londono
if (typeof me.onChange !== "undefined") { // safe to use the function me.onChange()
}
//or better yet
if (typeof me.onChange === "function") { // safe to use the function me.onChange()
}
Source : | Last Update : Wed, 25 Jan 23
Answered by : yann-deo
<div class="secondary info">Item</div>Code language: HTML, XML (xml)
Source : https://www.javascripttutorial.net/dom/css/check-if-an-element-contains-a-class/ | Last Update : Sat, 19 Jun 21
Answered by : kind-kinkajou-8wrwfmh2djgn
export const isClass = <T>(value: unknown): value is Constructor<T> => { return typeof value === "function" && typeof value.prototype === "object";
};
export type Constructor<T> = new (...args: unknown[]) => T;
Source : | Last Update : Sun, 24 Jul 22