According to this answer:
HTML 4.01 specifies that <a> elements may only contain inline elements. A <div> is a block element, so it may not appear inside an <a>.
But...
HTML5 allows <a> elements to contain blocks.
Well, I just tried selecting a <div class="m">
within an <a>
block, using:
Elements elems = a.select("m");
and elmes returns empty, despite the div being there.
So I am thinking: Either I am not using the correct syntax for selecting a div within an a or... Jsoup doesn't support this HTML5-only feature?
What is the right Jsoup syntax for selecting a div
within an a
?
Update: I just tried
Elements elems = a.getElementsByClass("m");
And Jsoup had no problems with it (i.e. it returns the correct number of such divs within a).
So my question now is: Why?
Why does a.getElementsByClass("m")
work whereas a.select("m")
doesn't?
Update: I just tried, per @Delan Azabani's suggestion:
Elements elems = a.select(".m");
and it worked. So basically the a.select()
works but I was missing the .
in front of the class name.