I have a long a web form. I’m wondering if I should bind() to each <input> element separately (what I really want) or should I only define one bind() all of the input elements then do an if-then inside the handler to handle the specific element?
I have a long a web form. I’m wondering if I should bind() to
Share
jQuery’s event handlers are implemented in JavaScript (they have to be).
In general, it’s best to use a single handler for the entire form, rather than a large number of individual elements. But jQuery’s
livefeature can help quite a lot, it does a lot of the plumbing for event delegation for you. For example:…watches all fields in your
formidform for focus events. If you’re using jQuery 1.4, that works even with thefocusevent in that example (even thoughfocusdoesn’t bubble, and so is usually tricky to use with event delegation). Prior to 1.4 that won’t work, but bubbling events likeclickand such do.