   toolbarElement:
     get: ->
       if @hasAttribute("toolbar")
-        document.getElementById(@getAttribute("toolbar"))
-      else
+        @ownerDocument?.getElementById(@getAttribute("toolbar"))
+      else if @parentElement
         toolbarId = "trix-toolbar-#{@trixId}"
         @setAttribute("toolbar", toolbarId)
         element = makeElement("trix-toolbar", id: toolbarId)

          @documentChangedSinceLastRender = false
          @notify("change")
      when "change", "attachment-add", "attachment-edit", "attachment-remove"
        @inputElement.value = Trix.serializeToContentType(this, "text/html")

    if @editorController
      triggerEvent("trix-#{message}", onElement: this, attributes: data)


  name:
    get: ->
      @inputElement?.name

  value:
    get: ->
      @inputElement?.value
    set: (@defaultValue) ->
      @editorController?.loadHTML(@defaultValue)

