0

I am defining a element in html

<pre id="dict"></pre>

and I am setting the inner html like this

document.getElementById("dict").innerHTML=<p>ಒಂದ್</p>;

but the render is gibberish

ಒಂದà³

expected result

ಒಂದ್

what am i missing here?

Yadu
  • 2,979
  • 2
  • 12
  • 27
  • 2
    What is the character set of the page? It has to be UTF-8 to work properly. – Pointy Aug 15 '20 at 16:32
  • 1
    My gibberish-detector is telling me something something windows-1252 – ASDFGerte Aug 15 '20 at 16:40
  • 1
    that was a simple fix, thanks for your time @Pointy – Yadu Aug 15 '20 at 16:41
  • no it wasnt explicitly set @ASDFGerte – Yadu Aug 15 '20 at 16:42
  • It's just that for reasons i've rather not have had, my eyes recently looked at so much "utf-8 being read as windows-1252", that the gibberish looked almost normal for me. Unsure, if there are other encoding changes causing the same result, but if you check utf-8 ಒಂದ್ mistakenly read as windows-1252 e.g. [here](http://string-functions.com/encodedecode.aspx), you'll see your example gibberish. – ASDFGerte Aug 15 '20 at 16:49
  • as the docs stated UTF-8 is default character encoding i didnt set it explicitly, should i remove the question? – Yadu Aug 15 '20 at 16:53

1 Answers1

0

This worked for me, please try the below snippet.

$("#dict").html("<p>ಒಂದ್</p>")
var value = $("#dict").text();
alert(value)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<pre id="dict"></pre>
Learner
  • 51
  • 1
  • 3