Javascript: using the replace method on hex or dec character using the hex or dec value itself -
i have html table sorting function sort in ascending or descending order column. show using down- , up- pointing small triangles hex code x25be; , x25b4; respectively.
the problem cannot replace these hex characters using replace method. can using character follows: mystring.replace('▴',''); not possible because javascript code generated , ▴ character cannot used in generating code.
it ok me use decimal codes #9662; , #9652; , if helps. see code sorttable function expressions tried, including suggestions post: javascript replaceing special characters
<html> <meta charset="utf-8"> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <head> <script type="text/javascript"> function sorttable(id,n) { table = document.getelementbyid(id); //i skipping sorting here. //the question is: how replace hex or dec characters? var ths = table.getelementsbytagname('th') (i = 0; < ths.length; i++) { //not working ths[i].innerhtml = ths[i].innerhtml.replace(' ▾',''); ths[i].innerhtml = ths[i].innerhtml.replace(' ▴',''); //also not working //https://stackoverflow.com/questions/4347366/javascript-replaceing-special-characters ths[i].innerhtml = ths[i].innerhtml.replace(/\x25be/g,''); ths[i].innerhtml = ths[i].innerhtml.replace(/[\xae\xfc]/g,''); //this works cannot use it! //ths[i].innerhtml = ths[i].innerhtml.replace(/[▴▾]/g,''); //mimick switching down-pointing small triangle up-pointing 1 if (i == n) { ths[i].innerhtml = ths[i].innerhtml + ' ▴'; } } } </script> </head> <body> <table id="tableid"> <tbody> <tr> <th onclick="sorttable('tableid',0)">col1 ▾</th> <th onclick="sorttable('tableid',1)">column 2 </th> </tr> <tr> <td>a</td> <td>100</td> </tr> <tr> <td>b</td> <td>20</td> </tr> <tr> <td>c</td> <td>50</td> </tr> </tbody> </table> </body> </html>
as @kelvin sherlock wrote in comment using \u25be works: .replace(' \u25be;','');
Comments
Post a Comment