 
     ontext: (el, text) ->
         delay.call el, ->
-            el._jquery.text(text)
+            @_jquery.text(text)
 
     onraw: (el, html) ->
-        delay.call el, =>
-            @animation.push ->
-                el._jquery?.html(html)
+        that = this
+        delay.call el, ->
+            that.animation.push =>
+                @_jquery?.html(html)
 
     onshow: (el) ->
         delay.call el, ->
-            el._jquery.show()
+            @_jquery.show()
 
     onhide: (el) ->
         delay.call el, ->
-            el._jquery.hide()
+            @_jquery.hide()
 
     onattr: (el, key, value) ->
         delay.call el, ->
             if value is undefined
-                el._jquery.removeAttr(key)
+                @_jquery.removeAttr(key)
             else
-                el._jquery.attr(key, value)
-
-    onreplace: (el, tag) ->
-        delay.call el, =>
-            @animation.push =>
-                return if removed el
-                _jquery = tag._jquery ? tag
-                return unless _jquery?.length > 0
-                el._jquery.replaceWith(_jquery)
-                # replaceWith isnt inplace
-                el._jquery = _jquery
-                if el is @builder
-                    el.jquery = _jquery
+                @_jquery.attr(key, value)
+
+    onreplace: (oldtag, newtag) ->
+        newtag._jquery_tracker ?= el:newtag
+        oldtag._jquery_tracker.el = newtag
+        that = this
+        delay.call oldtag, ->
+            newtag = newtag._jquery_tracker.el
+            delay.call newtag, ->
+                that.animation.push =>
+                    newtag = @_jquery_tracker.el
+                    return if removed(oldtag) or removed(newtag)
+                    _jquery = newtag._jquery ? newtag
+                    return unless _jquery?.length > 0
+                    oldtag._jquery.replaceWith(_jquery)
+                    # replaceWith isnt inplace
+                    for tag in [oldtag, newtag]
+                        tag._jquery = _jquery
+                        if tag is tag.builder
+                            tag.jquery = _jquery
 
     onremove: (el) ->
-        delay.call el.parent, ->
-            el._jquery?.remove()
+        if el._jquery?
+            el._jquery.remove()
             delete el._jquery
+        delete el._jquery_tracker
 
     onend: () ->
 #         @builder._jquery.data('dt-jquery', @template.xml)

    return if removed this
    # only when tag is ready
    if @_jquery?
        do job
    else
        @_jquery_delay ?= []
        @_jquery_delay.push(job)

release = () ->
    if @_jquery_delay?
        for job in @_jquery_delay
            job.call(this)
        delete @_jquery_delay


