This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
Since DOM starts to allow multiple nodes to be manipulated in bulk (e.g., node.before, node.after), does it make sense to allow multiple nodes to be inserted into a range as well? For example, range.insertNodes(nodes). Also have a quick question on the algorithm of node.before and likes: The before(nodes) method must run these steps: 1.If the context object does not have a parent, terminate these steps. 2.Run the mutation method macro. 3.Pre-insert node into the context object's parent before the context object. Shouldn't step 3 be something like "For each node in nodes ...", node was never defined in the algorithm. But maybe I missed something.
(In reply to Glen Huang from comment #0) > Since DOM starts to allow multiple nodes to be manipulated in bulk (e.g., > node.before, node.after), does it make sense to allow multiple nodes to be > inserted into a range as well? > For example, range.insertNodes(nodes). This can be done via range.insertNodes(documentFragment). > The before(nodes) method must run these steps: > > 1.If the context object does not have a parent, terminate these steps. > 2.Run the mutation method macro. > 3.Pre-insert node into the context object's parent before the context object. > > Shouldn't step 3 be something like "For each node in nodes ...", node was > never defined in the algorithm. But maybe I missed something. In step 2. we have "mutation method macro" which make DocumentFragment (when we have more than one node) or node, so this is correct.
Ah, that macro, I know I missed something. Thank you. About inserting document fragment into the range, this is exactly what I'm proposing. Instead of asking users to manually create it, DOM should take care of it, much like how it provides sugar like node.append, which is just document fragment + node.appendChild. In this case, range.insertNodes is sugar for document fragment + range.insertNode.
Or extend insertNode() if it doesn't breake anything: void insertNode((Node or DOMString)... nodes); but the name of the method will be misleading.
Or just range.insert(nodes), like node.appendChild -> node.append.
Why not make DocumentFragment easier to use instead? For example: ``` range.insertNode(new DocumentFragment(node1, 'a text node', node2)); range.insertNode(new DocumentFragment(document.getElementsByClassName('foo'))); range.insertNode([node1, node2]); range.insertNode(new Set([node1, node2])); // iterable ``` This prevents having to change the spec in a lot of places.
Do you know if there's any implementer interest for these ideas? And precedence in JavaScript libraries? I'm leaning towards closing this, but you can always open a new issue on GitHub.
FWIW, https://github.com/whatwg/dom/issues/new is the new place.