JQuery dynamic event handler

I came to the conclusion that dynamic event handlers can make my life much more easier, so I can write more cleaner and maintainable code. My idea was to add different class names to an element to bind different event handlers to it. This way, I could get rid of some global variables and switch case loops that i needed to manage my functions. The second advantage is, that you can chain event handlers to do things one after another.

Here is a small example that adds classnames to a button and binds dynamic event handlers to the class attribute. Depending on the class attribute an event handler fires an alert box that indicates which classname was added to the button.

The JQuery “.live()” function i no real event handler binding, but it works like charm for my idea.

Licensed under CC BY-NC-SA 4.0
Zuletzt aktualisiert am Jun 18, 2011 21:30 UTC
comments powered by Disqus
Developer / Inventor / Creator
Erstellt mit Hugo
Theme Stack gestaltet von Jimmy