3

I have many html entities, for example: 確定 (Japanese characters), that are being rendered as the string: 確定 , not as the characters, if I try:

var inputEl = document.createElement("input");

inputEl.value = "確定";

Does anyone know a workaround? I'm a little stumped.

1 Answers1

0

You can do this trick. Seems html entities are not decoding properly in your example. Therefore You can use trick function to decode them using temporary html div element.

function trick(x){
  var a = document.createElement('div');
  a.innerHTML = x;
  return a.innerHTML;
}

var inputEl = document.createElement("input");

inputEl.value = trick("確定");

document.getElementById('d').appendChild(inputEl);
<div id="d"></div>

Hope it helps

Shalitha Suranga
  • 1,138
  • 8
  • 24