I have some html buttons with a value contains html entities. For example
<input  type="button" name="sin" value="sin²" onClick="insertChar(this)">
<input  type="button" name="cos" value="cos²" onClick="insertChar(this)" >
<input  type="button" name="plus" value="+" onClick="insertChar(this)" >
values of these button is concated to a value of textarea in the html form. Suppose the value of textarea is "sin²+cos²". Now I want to replace the html entity ² with a char "2". I tried with this javascript code
String.prototype.replaceAll = function( token, newToken, ignoreCase ) {
    var _token;
    var str = this + "";
    var i = -1;
    alert(token+"----------------------");
    if ( typeof token === "string" ) {
        if ( ignoreCase ) {
            _token = token.toLowerCase();
            while( (
                i = str.toLowerCase().indexOf(
                    token, i >= 0 ? i + newToken.length : 0
                ) ) !== -1
            ) {
                str = str.substring( 0, i ) +
                    newToken +
                    str.substring( i + token.length );
            }
        } else {
            return this.split( token ).join( newToken );
        }
    }
return str;
};
The above code is working fine for replacing a character with another character, but it is not working for replacing a html entity with a char.
 
    