I'm using GWT and its underlaying DOM capabilities.
What I'm basically trying to achieve is :
div element holding some textspan elementsspan elements can be created dynamically by the end-usersThis is what it could look like :

At the startup of the application, and during end-users dynamic creation of spans, I have to do some Element and Nodes manipulations (creating, inserting, modifying, deleting). To achieve this, I have to go through the DOM tree to be able to find particular elements.
I'm looking for ways to reduce useless time spent at the startup of the application, where I build my div element (containing all the text and span elements).
Take this example :
DivElement outermostDiv = Document.get().createDivElement();
processText(outermostDiv, text); // text could be a Java String element
turnTheseIntoSpans(listOfSpans, outermostDiv); // listOfSpans could be a list of text that must be surrounded by span elements.
Let's imagine, that turnTheseIntoSpans do lots of modifications of the outermostDiv element using methods like : appendChild(), removeFromParent(), ...
My questions are :
Is it a good practise to modify outermostDiv and its childs before inserting it into the DOM ?
I can have access to outermostDiv childs, sibling of childs, without having added it to the DOM. I would like to understand how a browsable tree of elements exists even before outermostDiv is added to the DOM ?
Document.createDivElement() creates an object that implements com.google.gwt.dom.client.Node, by calling the following JavaScript:
return doc.createElement('div');
Such a node is not initially attached to the document tree, but even before it is, you can already perform most operations on it (except for the ones that would need its parent node, as this is still null).
Note: The node is created by the same document it will later be attached to (this is necessary, because nodes created by a different document may be incompatible - so you can't always attach all nodes everywhere).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With