Pregunta

I have a form that's ajaxed in, and within that form it generates new inputs, and these new inputs have events attached to them by the .live() within the initial ajaxed form.

So, the problem I'm having happens when I close this ajaxed form and then open it again without refreshing: I have 2 live events bound to each individual element that should only have 1 live event.

The way I see getting around this is preceding each .live() with a .die() to clear out all previously attached live() ?

I am wondering if there is a cleaner, or more appropriate way of handling this?

¿Fue útil?

Solución

You're aware how .live() works, right? You call it once, and the event handler attaches to the document and handles the event for all elements that match that selector, even if they're added in the future. You don't call .live() each time you add elements; if you're using it correctly, you only have to call .die() if you want to stop handling that particular event altogether, or want to change/replace the handler.

Short version: The cleaner, more appropriate alternative is to quit calling .live() when you don't need to.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top