When it comes to indexing in XPath, I feel like I’m missing something here.
If I have two table tags in an HTML document, and within the Chrome console I type
$x("//table[1]");
, I expect to get the first table tag on the page.
Instead, I get a list containing both table tags. I suspected it might have something to do with using
//
but using an absolute XPath expression yielded the same results.
I think this is a pretty simple misunderstanding, but I’m not seeing it when reading the docs.
//table[1]returns all tables that are the first table child of their respective parents.To get the first table use
/descendant::table[1]or in XPath 2.0(//table)[1].Here it is in the standard: