Table of Contents

<HTMLElement>.removeClass()

Removes a class from an HTMLElement.

Usage:
HTMLElement = Element.removeClass(className)
Member of:
HTMLElement
Parameters:
className – the name of the class to remove as String object, or as quoted string (required).
Returns:
The same HTMLElement that it was called on, thus allowing for command chaining.
Notes:
  • If the class to be removed does not exist, this method does nothing.
  • This method is a simple wrapper for the classList.remove() method. The only difference is that this function returns the HTMLElement and thus allows chaining other functions for neater and/or more compact code.

Examples

Simple example:

let foo = document.getElementById('foo');
foo.removeClass('bar');

Chaining allows for very compact code:

document.getElementById('foo').removeClass('bar').attr('data-value', '123');

… and also allows to write very neat and readable code:

document.getElementById('foo')
	.removeClass('bar')
	.attr('data-value', '123')
;

See also

More information