How to "boolean" symbol values?

How to "boolean" symbol values?


Hi, there,
I came up with this question. I would like to make a conditional statement. If the text content in an HTML element is equal to the celsius degree sign. How should I realize this?

var unit = document.querySelector("#unit");
if (unit.innerHTML == “&#8457”){
my statement;}

This does not seem to work.

Anyone out there has any idea?

Thank you.


How about comparing with the actual unit symbol?

if (unit.innerHTML == '℉') ...

That said, you may want to rely on state that you keep in the JS code instead of checking the text in HTML elements. For example, keep a boolean variable called isFahrenheit, then compare against this value when needed.


thank you so much! It works!


No, actually it does not work when I define a variable as ‘℉’.

I put
var isF = ‘℉’;
in my JS file.

Once I open the webpage, and type isF in my console. The console returns “℉”.


Do you have a codepen link?


I took a detour by separating the temperature unit into a regular degree sign and a letter. It works well.