5

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
sacabuche
  • 2,781
  • 1
  • 27
  • 35

3 Answers3

2

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:

Community
  • 1
  • 1
Anurag
  • 140,337
  • 36
  • 221
  • 257
0
$('.add-row a').click(my_function)

as long as my_function does not include return false; it shouldn't interfere with the existing functionality of that button

antyrat
  • 27,479
  • 9
  • 75
  • 76
metamemetics
  • 675
  • 1
  • 7
  • 10
0

The suggestions above do not work for this particular problem. I'll file a bug and ask if they can assign an ID to that link button, or fix it another way.

Edit: bug filed https://code.djangoproject.com/ticket/16359

Roel Kramer
  • 371
  • 3
  • 12