jQuery: adding change event handler with predefined function
So I have the following: var change_handler = function(element) { // ... do some fancy stuff ... } Now, I want to attach this to an element. Which is the better/best or more correct method? $('element_selector').change(change_handler(this)); Or... $('element_selector').change(function() { change_handler(this); }); And does it make any difference if you're passing the object to the function or not? Neither.. $('element_selector').change(change_handler); change_handler will be the so to speak pointer to the method and the argument of the element is already passed by jQuery If you were to use $(