XPath: Parent form of submit button
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).
精彩评论