FluentDOM\Query::removeAttr PHP Method

removeAttr() public method

Remove an attribute from each of the matched elements. If $name is NULL or *, all attributes will be deleted.
public removeAttr ( string | array $name ) : Query
$name string | array
return Query
    public function removeAttr($name)
    {
        $names = $this->getNamesList($name);
        $this->each(function (\DOMElement $node) use($names) {
            /** @noinspection PhpParamsInspection */
            $attributes = NULL === $names ? array_keys(iterator_to_array($node->attributes)) : $names;
            foreach ($attributes as $attribute) {
                if ($node->hasAttribute($attribute)) {
                    $node->removeAttribute($attribute);
                }
            }
        }, TRUE);
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Remove the attribute(s) on all selected element nodes
  *
  * @see ArrayAccess::offsetUnset()
  * @see FluentDOM::removeAttr()
  * @example properties/attr-unset.php Usage: Remove attribute properties
  * @param string|array $name
  */
 public function offsetUnset($name)
 {
     $this->_fd->removeAttr($name);
 }