Source Code:
(back to article)
Submit
Result:
Report an issue
<div id="containsClassExample" class="highlight"> This element's classes will be checked. </div> <button onclick="checkClass()">Check Class</button> <script> function checkClass() { const element = document.getElementById('containsClassExample'); if (element.classList.contains('highlight')) { alert('The element has the highlight class.'); } else { alert('The element does not have the highlight class.'); } } </script> <style> .highlight { background-color: yellow; } .text-large { font-size: 24px; } </style>