Search code examples
javacss-selectorshtml-parsingjsoup

How to check the type of an HTML element using jsoup


Given a HTML code snippet,

<div align="right">...<div>
<p class="text2">abc</p>

I have used jsoup to fetch all elements with their attribute, align set to right. Now I want to select the next sibling which i do using, el.nextElementSibling()

How do I verify that the next element is a p HTML element with a class of text2? I am new to jsoup and I am learning as I code. Any help would be appreciated! Thanks!


Solution

  • Use Element#getTagName, which gives you the name of the tag for that element. That same API page also gives you Element#classNames and a couple of other ways to look at the class attribute.