Accents and HTML entities in jQuery

So I've got a JSON file (pulled in from an API) where I'm doing some comparisons. I fetch the content of the JSON file and put it on some buttons (as button text). I then do a comparison test for equality between the button text and text in the JSON file.

This works in 99% of my use cases however:

Some words in my JSON file have accents on them (either ? or so on). When I try and do a comparison in jQuery, even though I'm using the:

   $(this).html()

for my button text, the equality test fails. The word in the JSON File might read:

   Frédéric Auguste Bartholdi 

but on my button it reads:

    Fr?d?ric Auguste Bartholdi

I thought if I did a comparison test such as:

    if($(this).html() === jsonFile[0])){...}

that would do the trick, but it doesn't seem to do it. For clarity (this) refers to my button and I can't really do much about the JSON file - can't be changed.

Does anyone have any ideas?

Answers 1

Related Articles