开发者

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

开发者 https://www.devze.com 2023-02-28 21:29 出处:网络
The following Jsoup statement works: Elements divs = document.select(\"div[class=mncls sbucls]\"); But the equivalent statment:

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 pr开发者_运维知识库oblem with class names that have spaces?


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).


Class names can not have a space. It's a CSS Specification, nothing to do with Jsoup. Technically mncls sbucls is two separate classes (mncls and sbucls).

The attribute selector works because you're selecting the class attribute where the value is mncls sbucls

0

精彩评论

暂无评论...
验证码 换一张
取 消