Skip to content Skip to sidebar Skip to footer

Comma-separated JQuery Selectors Performance

Please advise which way using selectors in jQuery is faster: $('.class1, .class2').html(''); or $('.class1').html(''); $('.class2').html('');

Solution 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


Solution 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%)

Post a Comment for "Comma-separated JQuery Selectors Performance"