I’ve done a test with performance of a jQuery selector.
The two selectors I have tested:
selection_width = total_width - ($('#commands .minimap').outerWidth() + $('#commands .actions').outerWidth());
And:
var commands = $('#commands');
selection_width = total_width - ($('.minimap', commands).outerWidth() + $('.actions', commands).outerWidth());
The second one is way faster than the first one. Is this correct or did I screw up the test somewhere?
In the first test, jQuery uses
document.querySelectorAll()(relatively fast) twice. In the second case, jQuery usesdocument.getElementById()(very fast) once anddocument.getElementsByClassName()(fast since you declared a context) twice.