Rct567 / DomQuery

PHP library for easy 'jQuery like' DOM traversing and manipulation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

->each returns DOMElement instead of DomQuery

torian257x opened this issue · comments

is that on purpose?

e.g. I cannot do

$dq->find('select[name="myname"]')->each(function ($el, $i){
            /** @var \DOMElement $el */
            $linktag = $el->parent(); //meeep parent doesn't exist on DOMElement

});

Yeh it is, see also: https://api.jquery.com/each/

If you want the result as an DomQuery instance you can just use a foreach loop.

@Rct567 ahh thanks
well in jquery you can do

->each(function(el){
var jel = $(el);
jel.parent();
});

is there something equivalent?

The constructor also accepts DOMNode/DOMElement, so just use new DomQuery (or DomQuery::create) instead of $ 😁