Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 389
sacabuche Avatar asked Nov 06 '22 13:11

sacabuche


1 Answers

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:

  • Binding dynamically created elements in jQuery
  • Event binding on dynamically created elements?
  • jQuery how to bind onclick event to dynamically added HTML element
  • adding a new dom element, want to rebind
like image 59
Anurag Avatar answered Nov 11 '22 04:11

Anurag