Menu

#196 :last-child selector doesn't work

closed
None
2022-04-09
2022-02-07
Mike
No
$html = '
<!doctype html>
<html>
<head><title></title></head>
<body>
    <p>This is just p</p>
    <p>This is p as last child</p>
</body>
</html>
';

$DOM = new simplehtmldom\HtmlDocument();
$DOM->load($html);

$selector = 'p:last-child';

print_r($DOM->find($selector)); 
// The array is empty while it should consist of one element

Discussion

  • LogMANOriginal

    LogMANOriginal - 2022-04-09
    • status: open --> closed
    • assigned_to: LogMANOriginal
     
  • LogMANOriginal

    LogMANOriginal - 2022-04-09

    Pseudo-classes are currently not supported. Refer to the documentation for the find method for a list of supported selectors.

    In this case, I suggest using the lastChild method, which will give you the same result as :last-child.

     

Log in to post a comment.