This relies on a really weird (but useful) thing: you can set properties on DOM elements, and they'll store that information for you. So if you come back to the same element, that data will still be there. I'm doing that here to store the current index, because people could potentially have multiple has_many forms inside the same parent form.