akonsu
akonsu

Reputation: 29576

need to fetch all elements after a specific element

is there an XPath expression that would return all <a> elements that follow the <span> in the document below? That is: [y,z].

<table>
  <tr>
    <td>
      <a href="x">x</a>
      <span>s</span>
      <a href="y">y</a>
      <a href="z">z</a>
    </td>
  </tr>
</table>

Upvotes: 1

Views: 33

Answers (2)

Tomalak
Tomalak

Reputation: 338386

//td/span/following-sibling::a

Upvotes: 1

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56212

Try this XPath:

//a[preceding-sibling::span]

Upvotes: 2

Related Questions