问题
Please advise which way using selectors in jQuery is faster:
$('.class1, .class2').html('');
or
$('.class1').html('');
$('.class2').html('');
回答1:
In terms performance they seems to be almost same(7-8%), but in terms of maintainability the first method will be better since there is no duplication of code
回答2:
check Performance
Single $('.class1, .class2').html('');
better as
- no duplication of code
- jQuery constructor is called only once which makes it little fast.(+3-4%)
来源:https://stackoverflow.com/questions/17972010/comma-separated-jquery-selectors-performance