summaryrefslogtreecommitdiff
path: root/src/Nodes/NodeTrait.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Nodes/NodeTrait.php')
-rw-r--r--src/Nodes/NodeTrait.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Nodes/NodeTrait.php b/src/Nodes/NodeTrait.php
index 2fbd240..ccc82ab 100644
--- a/src/Nodes/NodeTrait.php
+++ b/src/Nodes/NodeTrait.php
@@ -557,4 +557,21 @@ trait NodeTrait
$count -= ($count - $nodes->length);
}
}
+
+ /**
+ * Mimics JS's firstElementChild property. PHP only has firstChild which could be any type of DOMNode. Use this
+ * function to get the first one that is an DOMElement node.
+ *
+ * @return \DOMElement|null
+ */
+ public function getFirstElementChild()
+ {
+ foreach ($this->childNodes as $node) {
+ if ($node instanceof \DOMElement) {
+ return $node;
+ }
+ }
+
+ return null;
+ }
}