InnerText, Insertadjacentelement, insertAdjacentHTML, insertAdjacentText and other different _javascript techniques

Source: Internet
Author: User
InnerText property in IE Browser can get the current element filter out HTML Tags after the text content, at some point or more useful. But similar non-standard properties/methods are not necessarily supported in other browsers.
Similar like Insertadjacentelement, Insertadjacentelement, insertadjacenthtml, insertAdjacentText, etc. If you need to use these non-standard methods, or if the existing code uses these methods in large quantities, you must provide the corresponding prototype definitions for the other browsers. Like what:


var isMinNS5 = (navigator.appName.indexOf ("Netscape") >= 0 &&
Parsefloat (navigator.appversion) >= 5)? 1:0;

if (isMinNS5) {
HTMLElement.prototype.insertAdjacentElement = function (Where,parsednode) {
Switch (where) {
Case Beforebegin:
This.parentNode.insertBefore (Parsednode,this)
Break
Case Afterbegin:
This.insertbefore (Parsednode,this.firstchild);
Break
Case BeforeEnd:
This.appendchild (Parsednode);
Break
Case Afterend:
if (this.nextsibling) {
This.parentNode.insertBefore (parsednode,this.nextsibling);
}
else{
This.parentNode.appendChild (Parsednode)
}
Break
}
}
HTMLElement.prototype.insertAdjacentHTML = function (where,htmlstr) {
var r = This.ownerDocument.createRange ();
R.setstartbefore (this);
var parsedhtml = r.createcontextualfragment (HTMLSTR);
This.appendchild (parsedhtml)
}
HTMLElement.prototype.insertAdjacentText = function (where,txtstr) {
var parsedtext = document.createTextNode (TXTSTR)
This.insertadjacentelement (Where,parsedtext)
}
htmlelement.prototype.__definegetter__
(
"InnerText",
function () {
var anystring = "";
var ChildS = this.childnodes;
for (var i=0; i<childs.length; i++) {
if (childs[i].nodetype==1)
AnyString + = childs[i].tagname== "BR"? \n:childs[i].innertext;
else if (childs[i].nodetype==3)
AnyString + = Childs[i].nodevalue;
}

return anystring;
}
);
}

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.