javascript - Dynamic Unicode Generation into the DOM -


i have function linking method javascript library i'm working on. taking romanized korean , converting specific unicode sequences , re-inserting dom. resulting strings generates correct, re-insertion dom seems off...

for example: if have following in dom:

<ko>hangug-eo</ko>

the function meant convert accordingly, replacing hangug-eo &#54620;&#44397;&#50612; show on browser:

한국어 within <ko> tags...

the function string setting within dom follows:

function (){     var z=document.getelementsbytagname('ko');     for(x=z.length;x--;){         z[x].childnodes[0].data=kimchi.go(z[x].childnodes[0].data);     } } 

however, seems seems doing placing &# unicode entities straight dom without converting respective character equivalents... i'm seeing &#54620;&#44397;&#50612;

can please point out may doing wrong?

kimchi.go() function provides unicoded string...

you can set text directly using textcontent without having use html entities:

z[x].textcontent = '한국어'; 

but if need use html entities, use innerhtml instead

z[x].innerhtml = kimchi.go(z[x].childnodes[0].data); 

you can see latter in example below.

https://jsfiddle.net/nml3to8w/1/


Comments