1

My DOM:

<div class="testClass">
    <a><span>some text</span> but this is the only text i want to select</a> </div>

I want to get the "but this is the only text i want to select" without also selecting "some text". After looking through other stackoverflow posts, and reading docs, I still cannot find a way to accomplish this.

The following code prints both of the above strings, I:E "some text but this is the only text i want to select".

Elements results = doc.getElementsByClass("testClass").select("a:not(a>span)");

for (Element element : results) { System.out.println(element.text()); } 
Delected
  • 41
  • 4
  • I fixed this temporarily using `results.select("span").remove();` Although, there must be a cleaner way to do this – Delected Apr 13 '21 at 12:52

0 Answers0