document.getAnonymousElementByAttribute(this, "anonid", "test").id = "test1"; var s = document.createElement("span"); s.id = "test2"; document.getAnonymousElementByAttribute(this, "anonid", "test").appendChild(s); var s = document.createElement("span"); s.id = "test3"; var p = document.getAnonymousElementByAttribute(this, "anonid", "test"); p.appendChild(document.createTextNode("testing")); p.insertBefore(s, p.lastChild); Mozilla Bug 489925