I’m wondering which approach is better and why: A) One document on click with many selectors, B) multiple document on clicks.
Also is there a limit on selectors for A? Thanks.
A)
$(document).on('click', '#a, #b, #c, #d, #e', function(e){
});
vs
B)
$(document).on('click', '#a', function(e){
});
$(document).on('click', '#b', function(e){
});
$(document).on('click', '#c', function(e){
});
$(document).on('click', '#d', function(e){
});
$(document).on('click', '#e', function(e){
});
Option A is called multiple selector approach http://api.jquery.com/multiple-selector/ – Selects the combined results of all the specified selectors
Performance (Selectors) = id vs class vs tag vs pseudo vs. attribute selectors ==>
http://jsperf.com/id-vs-class-vs-tag-selectors/2
Advantages I see with multiple selector:
Recommendation
Please think of using
classattribute instead of so many id’s if all of them does same thingLike this