protected function toggleElementClass(DOMElement $domReference, $class, $toggle)
    {
        // Get all existing classes.
        $classes = array_filter(explode(' ', trim($domReference->getAttribute('class'))));

        // Add or remove the broken class from the link, depending on the link status.
        if ($toggle) {
            $classes = array_unique(array_merge($classes, [$class]));
        } else {
            $classes = array_diff($classes, [$class]);
        }

        if (!empty($classes)) {
            $domReference->setAttribute('class', implode(' ', $classes));
        } else {
            $domReference->removeAttribute('class');
        }
    }
protected function toggleElementClass(DOMElement $domReference, $class, $toggle)
    {
        // Get all existing classes.
        $classes = array_filter(explode(' ', trim($domReference->getAttribute('class'))));

        // Add or remove the broken class from the link, depending on the link status.
        if ($toggle) {
            $classes = array_unique(array_merge($classes, [$class]));
        } else {
            $classes = array_diff($classes, [$class]);
        }

        if (!empty($classes)) {
            $domReference->setAttribute('class', implode(' ', $classes));
        } else {
            $domReference->removeAttribute('class');
        }
    }
protected function toggleElementClass ( DOMElement $ domReference , $ class , $ toggle ) { // Get all existing classes. $ classes = array_filter ( explode ( ' ' , trim ( $ domReference -> getAttribute ( 'class' ) ) ) ) ; // Add or remove the broken class from the link, depending on the link status. if ( $ toggle ) { $ classes = array_unique ( array_merge ( $ classes , [ $ class ] ) ) ; } else { $ classes = array_diff ( $ classes , [ $ class ] ) ; } if ( ! empty ( $ classes ) ) { $ domReference -> setAttribute ( 'class' , implode ( ' ' , $ classes ) ) ; } else { $ domReference -> removeAttribute ( 'class' ) ; } }
Add the given css class to the DOM element.

@param DOMElement $domReference Element to modify.
@param string $class Class name to toggle.
@param bool $toggle On or off.
Add the given css class to the DOM element .