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);
}