public function attr(string $name, $val=null)
    {
        if ($val !== null) { // set attribute for all nodes
            foreach ($this->getElements() as $node) {
                $node->setAttribute($name, $val);
            }
            return $this;
        }
        if ($node = $this->getFirstElmNode()) { // get attribute value for first element
            return $node->getAttribute($name);
        }
    }
public function attr(string $name, $val=null)
    {
        if ($val !== null) { // set attribute for all nodes
            foreach ($this->getElements() as $node) {
                $node->setAttribute($name, $val);
            }
            return $this;
        }
        if ($node = $this->getFirstElmNode()) { // get attribute value for first element
            return $node->getAttribute($name);
        }
    }
public function attr ( string $ name , $ val = null ) { if ( $ val !== null ) { // set attribute for all nodes foreach ( $ this -> getElements ( ) as $ node ) { $ node -> setAttribute ( $ name , $ val ) ; } return $ this ; } if ( $ node = $ this -> getFirstElmNode ( ) ) { // get attribute value for first element return $ node -> getAttribute ( $ name ) ; } }
Get the value of an attribute for the first element in the set of matched elements
or set one or more attributes for every matched element.

@param string $name
@param string $val

@return $this|string|null
Get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element .