How to "boolean" symbol values?

How to "boolean" symbol values?
0

#1

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.


#2

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.


#3

thank you so much! It works!
Kyle


#4

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 “℉”.


#5

Do you have a codepen link?


#6

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

Thanks.