The variables target & parent are created to keep track of the latest changes - this seems a necessity especially for nesting.
Formalising this practice and keeping it consistent across different methods of manipulating the objects (markup/javascript) will ensure a more predictable behaviour.