What should I do if firefox does not support innerText during the test? In fact, it is very simple. This article provides you with a solution. If you are interested, you can refer to it and hope to help you with the js Code:
The Code is as follows:
Script
Window. onload = function (){
if(window.navigator.userAgent.toLowerCase().indexOf("msie")==0){ //firefox innerText
HTMLElement.prototype.__defineGetter__( "innerText",
function(){
var anyString = "";
var childS = this.childNodes;
for(var i=0; i
if(childS[i].nodeType==1)
anyString += childS[i].tagName=="BR" ? '\n' : childS[i].textContent;
else if(childS[i].nodeType==3)
anyString += childS[i].nodeValue;
}
return anyString;
}
);
HTMLElement.prototype.__defineSetter__( "innerText",
function(sText){
this.textContent=sText;
}
);
};
Var test = document. getElementById ("test ");
Var innerText_s = test. innerText;
If (innerText_s = undefined ){
Alert (test. textContent); // firefox
} Else {
Alert (test. innerText );
};
}
Script
Html code
Test1 test2