What is the most "proper" way to bind a function to the click event of a class that has elements appended frequently?
I've read that using the "onclick" attribute on an element is not advised. If this is true, why? using "onclick" seems like the most straightforward method at this point.
If onclick is not used, then every time a new element is added to a class, you would have to unbind the click function for all members of the class, and then rebind it to avoid a double binding. With onclick, the problem is avoided completely.
So, to avoid double bindings, wouldn't this be easier?
onclick='somefunction(this)'
instead of
$("#divid").click(function(){
// do something
});
(where we would have to check for existing bindings on previously existing elements of the class)