I'm generating content dynamically, so I'm often ending up with documentFragments
which I'm querying using querySelectorAll
or querySelector
returning a nodeList
of elements inside my documentFragment.
From time to time I would like to add an item to a list, but I can't find anything online on whether this is even possible.
I tried it like this:
document.querySelectorAll(".translate").item(length+1) = document.createElement("div");
and this:
document.querySelectorAll(".translate").shift(document.createElement("div"));
But both don't work (as expected)
Question:
Is it possible to manually add elements to a NodeList? I guess, not but asking nevertheless.
Thanks for some insights?
EDIT:
So more info: I'm generating a block of dynamic content, which I want to append to my page. By default the block is in English. Since the user is viewing the page in Chinese, I'm running a translator on the dynamic fragment, BEFORE appending it to the DOM. On my page, I also have an element, say a title, which should change depending on the dynamic content being added. My idea was to do this in one step = try to add an element to my nodeList
. But from writing it now... I guess not possible :-)
NodeList
later? – Wilberwilberforce