Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE HTML> <html> <head> <title>Title of the document</title> </head> <body> <div id="test" class="myClass">Welcome to W3Docs</div> <script> function hasClass(element, clsName) { return(' ' + element.className + ' ').indexOf(' ' + clsName + ' ') > -1; } let val1 = document.getElementById('test'); alert(hasClass(val1, 'myClass')); </script> </body> </html>