How can I check if body has specific class? This is my case:
<body class="foo foo1 foo3"></body>
How can I check if body has specific class? This is my case:
<body class="foo foo1 foo3"></body>
 
    
    There's now a super-easy way to do this:
document.body.classList.contains('my-class-name')
 
    
    document.getElementsByTagName("body")[0].className.match(/foo/)
 
    
     
    
    jQuery.hasClass works for me...
non jQuery answer, try if( document.body.className.match('foo') ) { ... }
 
    
    function hasClass(ele,cls) {
     return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
if(hasClass(document.getElementById("test"), "test")){//do something};
maybe this helps you :-)
With the use of jQuery it would be easier and less code but nevermind !
 
    
    This returns a string of true or false when looking for a specific body class using jQuery's .hasClass:
if ($("body").hasClass("modal-open")) {
                        $("body").removeClass("modal-open");
                    }
 
    
    You can use the Mozilla classList for this.
The linked page also has a cross-browser solution.
 
    
    This returns a string of true or false when looking for a specific body class using jQuery's .hasClass:
$("body").hasClass("your-class-name").toString();
