                 do job
             delete el._jquery_delay
         # insert into parent
-        delay el.parent, ->
+        delay.call el.parent, ->
             if el.parent is tpl.xml
                 el.parent._jquery = el.parent._jquery.add(el._jquery)
             else

                return # dont return emit result (which is either true or false)

    tpl.on 'text', (el, text) ->
        delay el, ->
            el._jquery.text(text)


    tpl.on 'attr', (el, key, value) ->
        delay el, ->
            el._jquery.attr(key, value)

    tpl.on 'attr:remove', (el, key) ->
        delay el, ->
            el._jquery.removeAttr(key)

    tpl.on 'remove', (el) ->

#       http://blog.stevenlevithan.com/archives/faster-than-innerhtml

# delay or invoke job immediately
delay = (job) ->
    # only when tag is ready
    if @_jquery?
        do job
    else
        @_jquery_delay ?= []
        @_jquery_delay.push(job)


jqueryify = (tpl) ->
    tpl.xml._jquery = $()
