> For the complete documentation index, see [llms.txt](https://i58215.gitbook.io/component-sdl2-en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://i58215.gitbook.io/component-sdl2-en/getting-started-with-the-library/work-with-class-identifiers.md).

# Work with class identifiers

Class identifiers are a very important part of the components, since the whole appearance is built on their basis.&#x20;

There are several methods for interacting with them. The names of the methods speak for themselves.

```cpp
bool hasClass(const string& className) const;
Component* removeClass(const string& className);
Component* addClass(const string& className);
Component* toggleClass(const string& className);
```

As an example, when interactions with class identifiers may be needed, this is the creation of a component for `Checkbox` in which the change of picture may occur due to the change of the class identifier from `unchecked` to `checked` and vice versa.

### Getting components by class identifier

As already described earlier, an identifier is used to access a component. But the component can be obtained by the class identifier, but with some caveats.&#x20;

Since several components can have the same class identifier, a **collection** of components with the given class identifier will be returned.&#x20;

To get the collection, use the `getElementsByClassName` method:

```cpp
Components getElementsByClassName(const string& className);
```

The `Components` class is a wrapper over a collection of components. The following actions can be performed on the collection:

1. Set each element of the collection to the same listener using the `addEventListener` method, which completely repeats the method of the `Component` class;

2. Call for each collection item a callback function with the first parameter passing a pointer to the current collection item using the `each` method

   ```cpp
   void each(function< void(Component* sender)> callback);
   ```

3. Get the component by number using the `at` method or the `operator[]`:

   ```cpp
   Component* at(size_t index);
   Component* operator[](size_t index);
   ```

4. Get the size of the collection using the `size` method:

   ```cpp
   size_t size();
   ```
