Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "div[class=mncls sbucls]" work whereas "div.mncls sbucls" doesn't?

The following Jsoup statement works:

 Elements divs = document.select("div[class=mncls sbucls]");

But the equivalent statment:

 Elements divs = document.select("div.mncls sbucls");

Doesn't work.

Why?

Does Jsoup have a problem with class names that have spaces?

like image 918
ef2011 Avatar asked Apr 26 '11 02:04

ef2011


1 Answers

A space is a descendent selector:

http://www.w3.org/TR/CSS2/selector.html#descendant-selectors

In your second example, when you put the space in there, you're denoting another element/class/selector, whereas in your first example you're explicitly grouping the selector into a single string (including the space).

like image 167
Jared Farrish Avatar answered Oct 19 '22 18:10

Jared Farrish