I'd like to add some logic to my code along the lines of:
var X = $('span').text()
$('body').append(X)
if (X == '▼') {
$('body').append('Yay!')
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span>▼</span>
However, as you can see from the above snippet, "Yay!" isn't appended to the body. So how can I check if a unicode character equals an escape sequence?
Use charCodeAt(0) and omit the '&#' in your string:
In javascript you can escape unicode characters with
\u
followed by the hexidecimal representation of the unicode value. See this for the conversion of your character. Near the bottom of the page it gives the Java escape code for the character which is the same as the JavaScript one.You can use
String.fromCharCode()
to create the character using the decimal number so that it matches the HTML entity you're using. Or just copy the character into a string literal and compare directly. This may be clearer or not depending on your situation.