Searches for an node in the DOM tree and returns first element or null.
public first ( string $expression, string $type = Query::TYPE_CSS, boolean $wrapElement = true ) : |
||
$expression | string | XPath expression or a CSS selector |
$type | string | The type of the expression |
$wrapElement | boolean | Returns \DiDom\Element if true, otherwise \DOMElement |
Résultat |
public function testFirst() { $html = '<ul><li>One</li><li>Two</li><li>Three</li></ul>'; $document = new Document($html, false); $list = $document->first('ul'); $item = $list->getNode()->childNodes->item(0); $this->assertEquals($item, $list->first('li')->getNode()); $list = new Element('ul'); $this->assertNull($list->first('li')); }