selector efficiency for dynamic elements: use class or id?
What is the best way to set a click event on an element that is created at run time?
Assume there is a dynamic list of items, each with a unique id, and all belonging to the same class.
Ideally, I'd like to set the click event on the class, and have new elements belonging to that class automatically registered for the click event. Through testing, it appears that the class selector is used to enumerate elements, and that a specific click event is stored with each specific element. If that is the case, then it seems to be best to just set a click event for each element id, as they are created, and not use the class selector.
Is this correct?
Also, do I need to unbind the event before removing an element? Is there any other cleanup required?
Thanks!