Dart: Adding child elements to DivElement programmatically

Viewed 1327

Say I want to add a ButtonElement to a DivElement programmatically, such that the resultant HTML is:

<div class="blah">
    <input type="button" name="whatever" value="Push Me!" />
</div>

In Dart, I see several methods on the DivElement class, and I'm not sure which one is appropriate for which context:

ButtonElement button = constructButtonElement();
DivElement div = constructDiv();

div.add(button);
div.nodes.add(button);
div.children.add(button);
// ???

Same goes for any other kind of container: BodyElement, SpanElement, etc. What's the correct way to dynamically add DOM elements to parent containers?

1 Answers
Related