Comma-separated jQuery selectors performance

一个人想着一个人 提交于 2019-12-23 18:25:24

问题


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

  1. no duplication of code
  2. jQuery constructor is called only once which makes it little fast.(+3-4%)


来源:https://stackoverflow.com/questions/17972010/comma-separated-jquery-selectors-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!