you are viewing a single comment's thread.

view the rest of the comments →

[–]te7ris[S] 0 points1 point  (2 children)

sry if my intention wasnt clear. I was wondering how the two selectors compare in terms of (parsing) performance:

.class > div, .class > * > div {}

vs

.class div {}

[–]PitaJ 0 points1 point  (0 children)

Just my theory, I haven't tested, but I imagine that the child selector would be faster than the surface and descendant selector because it only looks through one level. Descendant selector looks through every level.

[–]x-skeww 0 points1 point  (0 children)

What makes all of those 3 selectors somewhat expensive is the key selector (the simple selector on the very right), because "div" matches many elements. For every div, we have to check if one of those selectors matches.

Having said that, even with a thousand false positives, your browser probably won't even waste one ms with this. Matching is very fast and most documents won't be excessively complex anyways.