Work with class identifiers
Class identifiers are a very important part of the components, since the whole appearance is built on their basis.
There are several methods for interacting with them. The names of the methods speak for themselves.
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.
Since several components can have the same class identifier, a collection of components with the given class identifier will be returned.
To get the collection, use the getElementsByClassName
method:
The Components
class is a wrapper over a collection of components. The following actions can be performed on the collection:
Set each element of the collection to the same listener using the
addEventListener
method, which completely repeats the method of theComponent
class;Call for each collection item a callback function with the first parameter passing a pointer to the current collection item using the
each
methodGet the component by number using the
at
method or theoperator[]
:Get the size of the collection using the
size
method:
Last updated
Was this helpful?