This is not a good practice because you do not control which click events become unrelated. To improve this, there are two different approaches:
Use event namespaces (faster)
You can use the namespace to control that you only disable the click event that you are going to bind again:
$(selector).off('click.namespace').on('click.namespace', function(e) {
Use classes (fastest)
Use the classes added to the link to mark them as registered (this does not bind previously related events, but helps prevent multiple event bindings, which is a problem, in most cases you would use off (unbind) to on (bind):
$(selector).not('.registered').addClass('registered').on('click', function(e) {
You can even turn this into a little sexy plugin by writing:
$.fn.register = function(register_class) { register_class || (register_class = 'registered');
That way you can just call register for each selector:
$(selector).register().on('click', function(e) {
Or with a specific class if "registered":
$(selector).register('special_handler_registered').on('click', function(e) {
Performance?
If you are wondering about the performance of different handlers:
Check out this performance test here.
source share