I have searched around I cannot find a way to do this. I have a group of elements. I select one element from this group. How could I find the next element after this selected element?
Use the method nextElementSibling()
.
Example:
<body>
<p>First in family!</p>
<p>Second in family!</p>
<p>Third in family!</p>
</body>
Jsoup:
Element firstParagraph = doc.select("p:eq(0)").first();
Element secondParagraph = firstParagraph.nextElementSibling();
System.out.println(firstParagraph.text() + " " + secondParagraph.text());
Output: First in family! Second in family!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With