Skip to content

Instantly share code, notes, and snippets.

@jnorthrup
Forked from niloc132/HowDoIInnterHtml.java
Created February 4, 2014 18:22
Show Gist options
  • Save jnorthrup/8809337 to your computer and use it in GitHub Desktop.
Save jnorthrup/8809337 to your computer and use it in GitHub Desktop.
public class HowDoIInnerHtml implements EntryPoint {
@Override
public void onModuleLoad() {
Element body = Document.get().getBody();
DivElement newDiv = Document.get().createDivElement();
newDiv.setClassName("foo");
newDiv.setInnerText("Text in the div");
SpanElement newSpan = Document.get().createSpanElement();
newDiv.appendChild(newSpan);
body.appendChild(newDiv);
//page shows "Text in the div"
Window.alert("newDiv.innerHTML? " + newDiv.getInnerHTML() +
"\nspan is in div? " + (newSpan.getParentElement() == newDiv));
//alert shows "Text in the div <span></span>", true
body.setInnerHTML("");
Window.alert("newDiv.innerHTML? " + newDiv.getInnerHTML() +
"\nspan is in div? " + (newSpan.getParentElement() == newDiv));
//alert shows "", false ???
body.appendChild(newDiv);
//page shows blank
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment