Textcontent is equivalent to innertext in Firefox.

Source: Internet
Author: User

In IE and opear, DOM objects support the innertext attribute and can easily remove HTML tags.
However, Firefox does not support this attribute. Fortunately, DOM objects in FF support textcontent, which is equivalent to innertext.

Demo instance:
<P id = "testobj"> Hi, I'm <strong> cnlei </strong>. welcome to my homepage: <a href = "http://www.cnlei.com"> http://www.cnlei.com </a>. </P>
<SCRIPT type = "text/JavaScript">
Function getinnertext (OBJ ){
Return document. All? OBJ. innertext: obj. textcontent;
}
VaR STR = getinnertext (document. getelementbyid ("testobj "));
Alert (STR );
</SCRIPT>

Add the innertext attribute to the DOM object in Firefox:

// Add the innertext attribute to the DOM object in Firefox
If (lbrowser. isns6) {// Firefox innertext define
Htmlelement. Prototype. _ definegetter _ ("innertext ",
Function (){
Return this. textcontent;
}
);
Htmlelement. Prototype. _ definesetter _ ("innertext ",
Function (stext ){
This. textcontent = stext;
}
);
}

Alert (lbrowser. isns6 );
</SCRIPT>

Appendix DOM reference:
Firefox DOM reference: http://www.mozilla.org/docs/dom/domref/dom_shortTOC.html
Ie dom reference:
Http://msdn2.microsoft.com/en-us/library/ms533050.aspx

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.