How can I determine if a dynamically-created DOM element has been added to the DOM?

后端 未结 11 996
滥情空心
滥情空心 2020-12-02 20:07

According to spec, only the BODY and FRAMESET elements provide an \"onload\" event to attach to, but I would like to know when a dynamically-create

11条回答
  •  日久生厌
    2020-12-02 20:37

    Instead of walking the DOM tree up to the document element just use element.ownerDocument. see here: https://developer.mozilla.org/en-US/docs/DOM/Node.ownerDocument and do this:

    element.ownerDocument.body.contains(element)
    

    and you're good.

提交回复
热议问题