public function index($selector=null)
    {
        if ($selector === null) {
            if ($node = $this->getFirstElmNode()) {
                $position = 0;
                while ($node && ($node = $node->previousSibling)) {
                    if ($node instanceof \DOMElement) {
                        $position++;
                    } else {
                        break;
                    }
                }
                return $position;
            }
        } else {
            foreach ($this as $key => $node) {
                if ($node->is($selector)) {
                    return $key;
                }
            }
        }

        return -1;
    }
public function index($selector=null)
    {
        if ($selector === null) {
            if ($node = $this->getFirstElmNode()) {
                $position = 0;
                while ($node && ($node = $node->previousSibling)) {
                    if ($node instanceof \DOMElement) {
                        $position++;
                    } else {
                        break;
                    }
                }
                return $position;
            }
        } else {
            foreach ($this as $key => $node) {
                if ($node->is($selector)) {
                    return $key;
                }
            }
        }

        return -1;
    }
public function index ( $ selector = null ) { if ( $ selector === null ) { if ( $ node = $ this -> getFirstElmNode ( ) ) { $ position = 0 ; while ( $ node && ( $ node = $ node -> previousSibling ) ) { if ( $ node instanceof \ DOMElement ) { $ position ++ ; } else { break ; } } return $ position ; } } else { foreach ( $ this as $ key => $ node ) { if ( $ node -> is ( $ selector ) ) { return $ key ; } } } return - 1 ; }
Get the position of the first element within the DOM, relative to its sibling elements.
Or get the position of the first node in the result that matches the selector.

@param string|self|callable|\DOMNodeList|\DOMNode $selector

@return int $position
Get the position of the first element within the DOM relative to its sibling elements . Or get the position of the first node in the result that matches the selector .