3

Does JSoup selector select elements from right-to-left or left-to-right?

Take the 2 as example: #id .class1 and #id > .class1

coderz
  • 4,847
  • 11
  • 47
  • 70
  • 1
    You know you can test using online tool @ http://try.jsoup.org/ – Osa E Dec 04 '14 at 16:27
  • 1
    This is a great question, upvoted. If Jsoup follows the paradigm of Jquery's Sizzle engine (http://sizzlejs.com/) then it's from right to left. I believe it's from left to right though. I can't check it right now, but you can see the implementation here http://grepcode.com/snapshot/repo1.maven.org/maven2/org.jsoup/jsoup/1.7.2 , check the parser package. Specifically here http://grepcode.com/file/repo1.maven.org/maven2/org.jsoup/jsoup/1.7.2/org/jsoup/parser/TokenQueue.java#TokenQueue – Alkis Kalogeris Dec 05 '14 at 11:24

1 Answers1

0

Looking at the Documentation on the website, I see:

Elements resultLinks = doc.select("h3.r > a"); // direct a after h3

It seems like it must work from left to right, so it first selects every h3 and then it selects those h3 which have an a after them.

Looking at the code seems to confirm this.

Jonas Czech
  • 12,018
  • 6
  • 44
  • 65