insertAdjacentText and insertAdjacentHTML

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.