Comparing Unicode Code Label Values

I use the Unicode value '✔' to display the label in the text area.

Now I need to get the value in the text area and check if the character is present in it?

When I get the value of the text area, I get a flag without a tick symbol instead of a tick symbol.

How can I compare this Unicode value, exists or not?

// Not working. if( document.getElementById('location').value.charAt(0) == '&#10004') alert("symbol'); 
+6
source share
1 answer

Your problem is that ✔ is an HTML object that represents in HTML, but it is just a string in JavaScript. In JavaScript, you want '✔' (raw character) or '\u2714' :

 if(document.getElementById('location').value.charAt(0) == '\u2714') alert("symbol"); else alert("not there");​ 

Demo: http://jsfiddle.net/ambiguous/WCdCg/

The HTML &#....; notation uses decimal numbers, the JavaScript '\u....' notation uses hexadecimal. Converting 10004 to hexadecimal yields 2714. You can also use &#x....; in HTML if you want to use hexadecimal there as well, for example ✔ is ✔. Using just hexadecimal is probably easier than dealing with the base conversions.

+10
source

Source: https://habr.com/ru/post/908312/


All Articles