         # Note: unlike the DOM, we only emit DOMNodeInsertedIntoDocument
         # on the root of a removed subtree, meaning the handler should check
         # to see if it has children.
-        if parent._attachedToDocument
+        if parent._attachedToDocument && elem.nodeType != 11
             browser.emit 'DOMNodeInsertedIntoDocument',
                 target : elem
                 relatedNode : parent

                # internally, so we only want to emit instructions if there
                # is a parent element pointer, meaning this CSSStyleDeclaration
                # belongs to an element.
                if this._parentElement
                    browser.emit 'DOMStyleChanged',
                        target : this._parentElement
                        attribute : attr

    #
    # var oldChild = node.removeChild(child);
    adviseMethod html.Node, 'removeChild', (parent, args, rv) ->
        # Note: Unlike DOM, we only emit DOMNodeRemovedFromDocument on the root
        # of the removed subtree.
        if parent._attachedToDocument
            elem = args[0]
            browser.emit 'DOMNodeRemovedFromDocument',
                target : elem
                relatedNode : parent
