Textcontent innertext-equivalent attribute _javascript techniques under Firefox
Source: Internet
Author: User
Under IE and opear, DOM objects support the InnerText property, which makes it easy to remove HTML tags.
However, the attribute is not supported in Firefox, but the DOM object under FF supports Textcontent, which is equivalent to innertext.
Demo Example:
<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>
Adding InnerText properties to the DOM object under 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
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.