Which method correctly tests if an element has a specific class?
element.classList.contains('classname') correctly tests if an element has a specific class. The classList property returns a DOMTokenList representing the element's classes, and the contains() method checks if that list contains the specified class. This method is more reliable than string-based checks on the className property because it handles multiple classes correctly and doesn't require parsing space-delimited strings. The classList API also provides add(), remove(), and toggle() methods for convenient class manipulation.