开发者

XPath: Parent form of submit button

开发者 https://www.devze.com 2022-12-16 05:08 出处:网络
I want to use PHP and DomXPath::query to get the parent \"form\" element of a submit button. The variable $dom holds the complete DOM tree and $node represents the submit button as a DOM node.

I want to use PHP and DomXPath::query to get the parent "form" element of a submit button. The variable $dom holds the complete DOM tree and $node represents the submit button as a DOM node.

$query = '??????';
$xpath = new \DomXPath( $dom );

$parents = $xpath->query( $query, $node );

if ( $parents->length )
{

    $form = $parents->item( 0 );

}

I tried several queries, but until now I found no solution. I think it would开发者_Go百科 be easy if I had more time to read about that XPath syntax. I hope you can help. :)


$query = 'ancestor::form';

This assumes the submit button only has one ancestor that is a form (you cannot nest forms in HTML).

0

精彩评论

暂无评论...
验证码 换一张
取 消