Reputation: 6762
I have jquery code to show 3 items at a time
$('.a').show();
$('.b').show();
$('.c').show();
I can also achieve the same with
$('.a, .b, .c').show();
What is main difference between both codes? Is it only the code reduction or will there be any performance related changes with 2nd code?
Upvotes: 0
Views: 47
Reputation: 685
In more details, when You call
$('.a').show();
$('.b').show();
$('.c').show();
It works like that:
so You create 3 arrays.
When you this:
$('.a, .b, .c').show();
It means: find all elements with classes a, b, c and call method show, so you create just one array.
Upvotes: 1
Reputation: 85545
By the way you can use a common class to achieve that:
$('.common_class').show();
But with your question:
With first idea of code would perform one by one but with second idea of code will do once by searching the classes.
Upvotes: 1