When implementing ajax functionality, it's important to reinitialize Javascript event handlers after each ajax call. This is necessary because ajax calls can lead to significant changes on the page, resulting in uninitialized objects.
If you're interested, check out this jsfiddle example: Multiple additions of Javascript event handlers
Although the solution I have seems to be working fine, I want to ensure that it's the right approach for our needs. For instance, the globally defined variable:
MyCompany.field.bindedOnfocusSelector = MyCompany.field._focusEventHandler.bindAsEventListener(MyCompany.field);
feels somewhat awkward and lacks the ability to pass additional function arguments.
Another suggestion mentioned using the prototype $(smth).on(event)
, but I've encountered issues trying to implement it, particularly with cross-browser compatibility. In fact, even in this simplified example Trouble with on('focus') in jsFiddle: