For instance, you have a list of DOM elements, say, li (or table cell td). Suppose you are processing a click event, when user clicks on any element in the list (or cell).
I considered two approaches: 1. binding 'click' event to each element or 2. binding event to the parent ul, then find a target from the 'event.target'.
I chose the first, because it is straightforward, a bit more reliable and easier to maintain by everyone in the future. By reliability I mean there is no extra code that can introduce a bug. I understand that the first is less optimal.
So questions are:
1) I don't know how to measure the performance hit or how much more memory the script will consume in the first approach comparing to the second. How much overhead approximately I could have in the first case?
2) I asked colleagues and some people advised me to do the second approach. I was told that it is a good practice in itself, called an 'event delegation', while the first one is a bad code practice.
So I was intrigued. Is it really binding same event type to every element is a bad code practice?