Pregunta

I see that Dart has a BodyElement class, and that it has an innerHTML property.

I also see that you can access the current document's body via window.document.body, however, there are no getter/setter methods for this body property.

So I'm trying to link the two together: how I dyamically set the current document's body's inner HTML? I'm looking for something like:

String html = "<p><h1>I'm dynamic</h1>";
window.document.body = bodyElementFactory.newBodyElement(html);
¿Fue útil?

Solución 2

Some options:

querySelector('body').appendHtml("<p><h1>I'm dynamic</h1>");

or

querySelector('body').innerHtml = "<p><h1>I'm dynamic</h1>";

Otros consejos

this should work for dart 1.14+

String html = "<p><h1>I'm dynamic</h1>";
querySelector('body').setInnerHtml(html);

document.body returns BodyElement. You could do the following if you wanted:

document.body.innerHtml = "<h1>I'm dynamic</h1>";
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top