Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Crawler.php

function Crawler::attr

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

Parameters

string|null $default When not null: the value to return when the node or attribute is empty:

Throws

\InvalidArgumentException When current node is empty

File

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

Class

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

Namespace

Symfony\Component\DomCrawler

Code

public function attr(string $attribute, ?string $default = null) : ?string {
    if (!$this->nodes) {
        if (null !== $default) {
            return $default;
        }
        throw new \InvalidArgumentException('The current node list is empty.');
    }
    $node = $this->getNode(0);
    return $node->hasAttribute($attribute) ? $node->getAttribute($attribute) : $default;
}
RSS feed
Powered by Drupal