Search code examples
jquerydjangodjango-adminjquery-events

How to bind events with jQuery in django admin when new *Inline is added


I made a jQuery function that binds some fields, but it doesn't work when I add a new inline.

The main problem is that I don't know how to detect the insertion in DOM and bind it to my function.


Solution

  • Use the live or delegate functions to bind to form elements. They will continue working even after you insert new form elements, and you don't need to re-attach the event handlers every time.

    Related questions: