Is it possible to append an element to a JavaScript nodeList?

前端 未结 5 1764

I\'m generating content dynamically, so I\'m often ending up with documentFragments which I\'m querying using querySelectorAll or querySelector

5条回答
  •  一个人的身影
    2021-02-13 06:15

    Unlike previously described element selection methods, the NodeList returned by querySelectorAll()is not live: it holds the elements that match the selector at the time the method was invoked, but it does not update as the document changes. [1]

    The NodeList in this case is not alive, so if you add/remove anything to/from it, then it won't have any effect on the document structure.

    A NodeList is a read-only array-like object. [1]

    [1]: JavaScript: The Definitive Guid, David Flanagan

提交回复
热议问题