About 1,060,000 results
Open links in new tab
  1. HTML DOM Element classList Property - W3Schools

    A list of the class names of an element. Note The classList property is read-only, but you can use the methods listed below, to add, toggle or remove CSS classes from the list:

  2. Element: classList property - Web APIs | MDN - MDN Web Docs

    Apr 3, 2025 · The Element.classList is a read-only property that returns a live DOMTokenList collection of the class attributes of the element. This can then be used to manipulate the class list. Using classList is a convenient alternative to accessing an element's list of classes as a space-delimited string via element.className.

  3. JavaScript classList: Manipulating CSS properties of an Element

    Use the add() and remove() methods to add CSS classes to and remove CSS classes from the class list of an element. Use the replace() method to replace an existing class with a new one. Use the contains() method to check if the class list of an element contains a specified class.

  4. javascript - Is there a way to add/remove several classes in one …

    Jun 20, 2012 · The new spread operator makes it even easier to apply multiple CSS classes as array: const list = ['first', 'second', 'third']; element.classList.add(...list);

  5. JavaScript classList() property and methods explained

    May 29, 2021 · Let's learn how to manipulate an HTML element's classes using JavaScript classList() property

  6. HTML DOM classList Property - GeeksforGeeks

    Jun 13, 2023 · The classList Property is a read-only property. This property uses “classList.length” property which returns the class names of the element in the form of DOMTokenlist (set of space-separated tokens). However, this property is to use add, remove and toggle CSS classes on an element. NOTE: The classList property is not supported in IE9 and earlier.

  7. javascript - How to get class list of the element? - Stack Overflow

    May 4, 2022 · I would like to access the class list of the html element (that is in this case I'd like to know if my-class is set on html): ... How can I do that with JavaScript? Select the element and then classList: This is also valid, +1. ^^ First I was laughing when you've done '.my-class' :)) that was valid but defeated the purpose of the question.

  8. How does classList Work in JavaScript? - Scaler Topics

    May 4, 2023 · The classList in JavaScript is a read-only property that is used to modify CSS classes and returns CSS classes. What is the JavaScript classList Property? The Classlist in JavaScript property allows you to powerfully manipulate the classes(the group of HTML elements) attached to an HTML Element .

  9. The Power of classList: Toggling Classes Easily in JavaScript

    Dec 10, 2024 · The classList API is a powerful and elegant solution for managing CSS classes in JavaScript. Its straightforward methods make it easy to add, remove, exchange, or toggle classes without the hassle of string manipulation.

  10. HTML Element classList Property: Element Class List

    Feb 11, 2025 · What is the classList Property? The classList property is part of the HTML DOM API and allows JavaScript to interact with an element’s CSS classes. It is particularly useful for: Dynamically changing the appearance of elements based on user interaction or application state.

Refresh