You are here

public function Crawler::attr in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/dom-crawler/Crawler.php \Symfony\Component\DomCrawler\Crawler::attr()

Returns the attribute value of the first node of the list.

Parameters

string $attribute The attribute name:

Return value

string|null The attribute value or null if the attribute does not exist

Throws

\InvalidArgumentException When current node is empty

File

vendor/symfony/dom-crawler/Crawler.php, line 517

Class

Crawler
Crawler eases navigation of a list of \DOMElement objects.

Namespace

Symfony\Component\DomCrawler

Code

public function attr($attribute) {
  if (!count($this)) {
    throw new \InvalidArgumentException('The current node list is empty.');
  }
  $node = $this
    ->getNode(0);
  return $node
    ->hasAttribute($attribute) ? $node
    ->getAttribute($attribute) : null;
}