← Back to Index

.hasClass()

Determine whether any of the matched elements are assigned the given class.

Examples

1. Check for class

// <div id="menu" class="open"></div>
const isOpen = $('#menu').hasClass('open');

Result

true

2. Check in a set

const hasError = $('input').hasClass('error');

Result

// Returns true if *at least one* element has the class
true

Parameters

Parameter Type Description
className string The class name to search for.

Returns: Boolean.