diff --git a/src/Dom/Elements.php b/src/Dom/Elements.php index cf94971..c57d20f 100644 --- a/src/Dom/Elements.php +++ b/src/Dom/Elements.php @@ -166,6 +166,34 @@ public function __call($name, $arguments) return $obj; } + /** + * Iterating elements + * + * @param callable $callback + * + * @return $this + */ + public function each(callable $callback) + { + $break = false; + $this->elements->each(function ($dom) use ($callback, &$break) { + if ( ! $dom || $break) { + return; + } + $orig = $dom; + $dom = new Elements(pq($dom)); + if (false === call_user_func($callback, $dom)) { + $dom = $orig; + $break = true; + } else { + $dom = $dom->getDOMDocument(); + } + unset($orig); + }); + + return $this; + } + /** * Iterating elements * @@ -184,7 +212,7 @@ public function map($callback) /** * Gets the attributes of all the elements * - * @param $attr HTML attribute name + * @param string $attr HTML attribute name * @return \Illuminate\Support\Collection|\Tightenco\Collect\Support\Collection */ public function attrs($attr)