Say I have an element like this...
<math xmlns="http://www.w3.org/1998/Math/MathML"> <mo class="symbol">α</mo> </math>
Is there a way to get the unicode/hex value of alpha α
, α
, using JavaScript/jQuery? Something like...
$('.symbol').text().unicode(); // I know unicode() doesn't exist $('.symbol').text().hex(); // I know hex() doesn't exist
I need α
instead of α
and it seems like anytime I insert α
into the DOM and try to retrieve it right away, it gets rendered and I can't get α
back; I just get α.
Using mostly plain JavaScript, you should be able to do:
function entityForSymbolInContainer(selector) { var code = $(selector).text().charCodeAt(0); var codeHex = code.toString(16).toUpperCase(); while (codeHex.length < 4) { codeHex = "0" + codeHex; } return "&#x" + codeHex + ";"; }
Here's an example: http://jsfiddle.net/btWur/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With