== .hasClass ==

.hasClass()

Checks if an HTMLElement has a specific class attached.
Usage:
[[mdn>Web/JavaScript/Reference/Global_Objects/Boolean|Boolean]] = Element''.hasClass''(className)
Member of:
Element, any valid [[mdn>Web/API/HTMLElement|HTMLElement]].
Parameters:
className – the name of the class to check for, as [[mdn>JavaScript/Reference/Global_Objects/String|String]] object or as quoted string (required).
Returns:
[[mdn>Web/JavaScript/Reference/Global_Objects/Boolean|Boolean]] – ''true'' if the class is attached, ''false'' if it is not.
Notes:
* This function is a simple wrapper for the [[mdn>Web/API/Element/classList|classList]]''.contains()'' function and only provides a slightly more convenient way of referencing this property.
===== Examples ===== Simple example: let foo = document.getElementById('foo'); if (foo.hasClass('bar')) { … }; ===== See also ===== * [[toolbox:classes:addclass:index|.addClass()]] * [[toolbox:classes:removeclass:index|.removeClass()]] * [[toolbox:classes:toggleclass:index|.toggleClass()]] ===== More information ===== * [[mdn>Web/API/HTMLElement|HTMLElement]] on MDN. * [[mdn>Web/API/Element/classList|classList]] on MDN.