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