質問

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.

役に立ちましたか?

解決

Just use the actual character:

if(document.getElementById("name").innerHTML == "Informació") // is that Catalan?
    // ..
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top