javascript if class exists code example
Example 1: jquery check if element exists
// Check if an element currently exists
if ($('#element').length) {
}
Example 2: javascript check if element has class
if(document.getElementById("myElmentID").classList.contains("hidden")){
// I have the 'hidden' class
}
Example 3: check if a class exists javascript
const element = document.querySelector("#box");
element.classList.contains("active");
Example 4: check if a class exists javascript
<div id="box" class="active"></div>