Comparing UTF-8 letterlike symbols

334
May 29, 2017, at 01:32 AM

I have an HTML document that looks something like this:

...
<p>Ambient temperature:</p>
<p class="big"><span id="ambientTempValue">23.6</span> <span id="ambientTempUnit">&#8451;</span></p>
...

I want to compare the value of #ambientTempUnit to check whether it's Fahrenheit or Celsius, but since the unit is in hex encoded format, jQuery simply returns the decoded version (degree of Celsius in this example). So, the question is, how can I compare those. There's probably a function that decodes the hex value but I had no luck finding it on Google. Thank you in advance!

Answer 1

It's a decimal number, formulated as a XML character reference.

$('<span>&#8451;</span>').text() === String.fromCodePoint(8451);
$('<span>&#8451;</span>').text().charCodeAt(0) === 8451;
Answer 2
<!DOCTYPE html>
<html>
<body>
<p>Ambient temperature:</p>
<p class="big"><span id="ambientTempValue">23.6</span> <span id="ambientTempUnit">&#8451;</span></p>
<p id="demo"></p>
<script>
if(document.getElementById("ambientTempUnit").innerHTML == "℃"){
document.getElementById("demo").innerHTML = "It's like totaly celsius man";
}
if(document.getElementById("ambientTempUnit").innerHTML == "℉"){
document.getElementById("demo").innerHTML = "It's like totaly fahrenheit man";
}
if(document.getElementById("ambientTempUnit").innerHTML == "K"){
document.getElementById("demo").innerHTML = "It's like totaly kelvin man";
}
</script>
</body>
</html> 
READ ALSO
Change color of &lt;li&gt; in &lt;ul&gt;

Change color of <li> in <ul>

I have code with some <li> in <ul>

164
How to create a modal type form in click event

How to create a modal type form in click event

I am looking for a plugin that could make a modal type form as the example of the image, i have tried with tolltipster plugin with no luck

227
Dynamic template re-rendering with knockout

Dynamic template re-rendering with knockout

I have the following template in one of my views:

261
Apache File-Upload isMuştiPartContent Return False

Apache File-Upload isMuştiPartContent Return False

I dont understand why returned false2 html form 1 for update image, main form for save entity

395