1

I am using charset=utf-8 character encoding and I am getting a weird symbol when I use "±" in my code. I am trying to output a text string like this:

.text('GMT Standard Time (UTC ±0)')

but I am getting this instead: GMT Standard Time (UTC �0)

What is the weird question mark character for? How to escape and properly display ± instead?

hnnnng
  • 481
  • 4
  • 21
  • 6
    Are you *sure* your page is using UTF-8 encoding? – Pointy Feb 08 '22 at 13:49
  • 1
    Yes, this is in my source: – hnnnng Feb 08 '22 at 13:50
  • 7
    You don’t need _escaping_, you need _**proper** encoding_. UTF-8 must be **everywhere**: your text file must be stored as UTF-8, the HTML needs to be served as UTF-8, [``](//developer.mozilla.org/docs/Web/HTML/Element/meta#attr-charset) needs to be used. – Sebastian Simon Feb 08 '22 at 13:50
  • 5
    The `meta` tag just declares what encoding is used. But it can lie. I can save a file in EBCIDC and use a `meta` tag that says it's UTF-8. Also note the `http-equiv` value; that means that tag is being used instead of an appropriate HTTP header. The web server should be in charge of setting the appropriate `Content-Type` header. – Heretic Monkey Feb 08 '22 at 13:55
  • 3
    @SebastianSimon you are absolutely right. I re-saved the js file with notepad as utf-8 and now it's working fine. Thank you! :D – hnnnng Feb 08 '22 at 13:56
  • 3
    `.html('GMT Standard Time (UTC ±0)')` – freedomn-m Feb 08 '22 at 14:21
  • @SebastianSimon I'll accept your insight if you post it as an answer. Thanks again. – hnnnng Feb 14 '22 at 02:23

0 Answers0