How do I add text to an HTML element in Dart? How do I add text to an HTML element in Dart? dart dart

How do I add text to an HTML element in Dart?


You can use Element.text to set the text content of the element or Element.appendText to add a text after the last child of the element :

import 'dart:html';main() {  var elem = new DivElement();  // replace content with the text  elem.text = "the text";  // add a text after the last child of this element  elem.appendText("the text");}


New syntax of previous answer:

import 'dart:html';main() {  var elem = new DivElement();  elem.appendText("the text");}

There is new import style and method appendText(String text) for adding the specified text after the last child.