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 == โ℉โ){
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!
Kyle
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?
yes.
I took a detour by separating the temperature unit into a regular degree sign and a letter. It works well.
Thanks.