QueryPath\DOMQuery::remove PHP Method

remove() public method

In other words, each item that matches the selector will be remove from the DOM document. The returned DOMQuery wraps the list of removed elements. If no selector is specified, this will remove all current matches from the document.
See also: replaceAll()
See also: replaceWith()
See also: removeChildren()
public remove ( string $selector = null )
$selector string A CSS Selector.
    public function remove($selector = null)
    {
        if (!empty($selector)) {
            // Do a non-destructive find.
            $query = new QueryPathEventHandler($this->matches);
            $query->find($selector);
            $matches = $query->getMatches();
        } else {
            $matches = $this->matches;
        }
        $found = new \SplObjectStorage();
        foreach ($matches as $item) {
            // The item returned is (according to docs) different from
            // the one passed in, so we have to re-store it.
            $found->attach($item->parentNode->removeChild($item));
        }
        // Return a clone DOMQuery with just the removed items. If
        // no items are found, this will return an empty DOMQuery.
        return count($found) == 0 ? new static() : new static($found);
    }