You are here

public function QueryPath::removeClass in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/QueryPath.php \QueryPath::removeClass()
  2. 7.2 QueryPath/QueryPath.php \QueryPath::removeClass()

File

QueryPath/QueryPath.php, line 1539

Class

QueryPath

Code

public function removeClass($class) {
  foreach ($this->matches as $m) {
    if ($m
      ->hasAttribute('class')) {
      $vals = explode(' ', $m
        ->getAttribute('class'));
      if (in_array($class, $vals)) {
        $buf = array();
        foreach ($vals as $v) {
          if ($v != $class) {
            $buf[] = $v;
          }
        }
        if (count($buf) == 0) {
          $m
            ->removeAttribute('class');
        }
        else {
          $m
            ->setAttribute('class', implode(' ', $buf));
        }
      }
    }
  }
  return $this;
}