DiDom\Element::has PHP Method

has() public method

Checks the existence of the node.
public has ( string $expression, string $type = Query::TYPE_CSS ) : boolean
$expression string XPath expression or CSS selector
$type string The type of the expression
return boolean
    public function has($expression, $type = Query::TYPE_CSS)
    {
        return $this->toDocument()->has($expression, $type);
    }

Usage Example

示例#1
0
 public function testHas()
 {
     $document = new \DOMDocument();
     $document->loadHTML('<div><span class="foo">bar</span></div>');
     $node = $document->getElementsByTagName('div')->item(0);
     $element = new Element($node);
     $this->assertTrue($element->has('.foo'));
     $this->assertFalse($element->has('.bar'));
 }