FluentDOM\Query::data PHP Method

data() public method

Read a data attribute from the first node or set data attributes on all selected nodes.
public data ( string | array $name, $arguments ) : mixed
$name string | array data attribute identifier or array of data attributes to set
return mixed
    public function data($name, ...$arguments)
    {
        if (count($arguments) == 0 && !is_array($name)) {
            //reading
            if ($node = $this->getFirstElement()) {
                $data = new Query\Data($node);
                return $data->{$name};
            }
            return NULL;
        }
        $values = $this->getSetterValues($name, isset($arguments[0]) ? $arguments[0] : NULL);
        $this->each(function (\DOMElement $node) use($values) {
            $data = new Query\Data($node);
            foreach ($values as $dataName => $dataValue) {
                $data->{$dataName} = $dataValue;
            }
        }, TRUE);
        return $this;
    }