Selector performance - 'E # id' vs '#id' - in CSS and jQuery

When using selectors in CSS and jQuery, are there differences in performance between using 'E#id' and #id , where E is any HTML element? If so, does this only apply to some layout engines and / or JavaScript engines?

+4
source share
2 answers

Browsers read selectors from right to left, so little can be obtained by prefixing something before an identifier; he is redundant at this point. Source: Writing Effective CSS from Mozilla

Here is an example of the real world to test it for yourself. TL: DR; it doesn't seem to matter much to make a difference.

Relevant further reading from the previous stack overflow question

+3
source

1) He believed that using an identifier for CSS was not good practice. It should be used when manipulating content through javascript.

2) Above the CSS qualification selector with the tag name ul.top-nav or ul # top-nav will only increase the overhead on the browser, since it must match both the tag and the class / identifier. Therefore, avoid over-qualifying the selector.

0
source

Source: https://habr.com/ru/post/1393094/


All Articles