Seth Ladd
Seth Ladd

Reputation: 120799

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

I would like to add some text to an element in the DOM. How do I do this in Dart?

Upvotes: 2

Views: 1208

Answers (2)

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76353

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");
}

Upvotes: 1

northewind
northewind

Reputation: 33

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.

Upvotes: 0

Related Questions