Well, the #id
selector is faster than the class selector because: (a) there can only be one element with a given id value; (b) browsers can contain an id -> element
map, so the #id
selector can work as fast as viewing a single map.
Further, the first option proposed above is definitely faster because it avoids the second search, thereby reducing the total search time based on the selection by 2 times.
Finally, you can use the “Chrome Developer Tools” Profiler selector (in the Profiles panel) to determine how long the browser takes to process the selectors on your page (match + apply styles to the corresponding elements.)
source share