I have an ajax app that will run functions on every interaction. I’d like to be able to run my setup function each time so all my setup code for that function remains encapsulated. However, binding elements more than once means that the handler will run more than once, which is obviously undesirable. Is there an elegant way in jQuery to call bind on an element more than once without the handler being called more than once?
Share
You could attach the event to
documentwith theone()function:Once run, this event handler is removed again so that it will not run again. However, if you need the initialization to run before the click event of some other element, we will have to think of something else. Using
mousedowninstead ofclickmight work then, as the mousedown event is fired before the click event.