1

In HTML, there are character entities to input any type of character. In javascript, they don't work in strings.

I want to compare a string with an elements value with an accent (written in Spanish):

HTML element:

<h1>Informaci&oacute;n</h1>

JS comparing to string:

if(document.getElementById("name").innerHTML == "Informaci&oacute;n")
    // ..

The JavaScript doesn't think the two elements are equal. I'm pretty sure I cannot type in a special character like an o with acute in Notepad++ and then escape it in JavaScript.

Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
  • You can in fact type the special character into your text editor and put it directly into the JavaScript string, so long as you're being careful to keep the MIME types straight. – Pointy Dec 05 '13 at 23:31
  • Also there's an "n" at the end of the text in the element you posted. – Pointy Dec 05 '13 at 23:31
  • @Pointy I know. The word is Información, with an n following the o with acute – Jonathan Lam Dec 05 '13 at 23:35
  • 1
    OK well if the straight character itself causes problems, you can try `"Informaci\u00F3n"` instead. – Pointy Dec 05 '13 at 23:40

1 Answers1

1

Just use the actual character:

if(document.getElementById("name").innerHTML == "Informació") // is that Catalan?
    // ..
bfavaretto
  • 71,580
  • 16
  • 111
  • 150