Which CSS selector is faster in performance? Class in Class vs tagName in Class? -
note: question not have similar match on so.
i aware css selectors read right left. aware css class selectors should not additionally qualified tagname.
but among these faster (not talking specificity):
.group div { ... .group .item { ...
for html:
<div class="group"> <div class="item"></div> </div>
since right left, doesn't mean in first case, browser search div
s (and faster) compared second case, browser search every element has class of item
(before comparing parent .group
class)?
i expect .group .item
(neglibibly) faster.
that's because, probably, number of div
elements greater number of elements class item
.
so if use .group div
, every div
match div
part, , browser have ensure there .group
ancestor. if use .group .item
, every .item
match .item
part, , browser have ensure there .group
ancestor.
for better performance, want avoid false positives, , if selector not going match element, want reject possible. .group .item
should faster if there less .item
div
.
anyways, use child selectors instead of descendant ones if can. seems reasonable formers faster.
Comments
Post a Comment