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.

1 Like

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.