Inserts the specified HTML fragment at the front, back, first child element, and after the last child element, four places before a DOM element. Other browsers support it successively. Only Firefox does not support, even the newly released ff4. insertAdjacentHTML has been adopted by HTML5.
if (htmlelement.prototype.insertadjacenthtml = = undefined) {
Htmlelement.prototype.insertadjacentelement = function (where, node) {
Switch (where) {
Case "Beforebegin":
This.parentnode.insertbefore (node, this);
Case "Afterbegin":
This.insertbefore (node, this.firstchild);
Case "BeforeEnd":
This.appendchild (node);
Case "Afterend":
if (this.nextsibling)
This.parentnode.insertbefore (node, this.nextsibling);
Else
This.parentnode.appendchild (node);
Break
}
}
htmlelement.prototype.insertadjacenthtml = function (where, HTML) {
var r = This.ownerdocument.createrange ();
R.setstartbefore (this);
var parsedhtml = r.createcontextualfragment (HTML);
This.insertadjacentelement (where, parsedhtml);
}
Htmlelement.prototype.insertadjacenttext = function (where, txt) {
var parsedtext = document.createtextnode (TXT);
This.insertadjacentelement (where, parsedtext);
}
}