HtmlObject\Traits\Tag::addClass PHP Method

addClass() public method

Add one or more classes to the current field.
public addClass ( string $class )
$class string The class(es) to add
    public function addClass($class)
    {
        if (is_array($class)) {
            $class = implode(' ', $class);
        }
        // Create class attribute if it isn't already
        if (!isset($this->attributes['class'])) {
            $this->attributes['class'] = null;
        }
        // Prevent adding a class twice
        $classes = explode(' ', $this->attributes['class']);
        if (!in_array($class, $classes)) {
            $this->attributes['class'] = trim($this->attributes['class'] . ' ' . $class);
        }
        return $this;
    }