How is the jQuery selector $('#foo a') evaluated?
问题 As a example of jQuery code (https://coderwall.com/p/7uchvg), I read that the expression $('#foo a'); behaves like this: Find every a in the page and then filter a inside #foo . And it does not look efficient. Is that correct? And if yes, how should we do that in a better way? 回答1: That is correct - Sizzle (jQuery's selector engine) behaves the same way as CSS selectors. CSS and Sizzle selectors are evaluated right-to-left, and so #foo a will find all a nodes, then filter those by nodes that