Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: Get symbol unicode from Font Awesome

Lets say I have camera-retro icon with unicode: '\uf083'. Now camera-retro icon in FontAwesome has unicode of '\f083'. How would I get the original unicode of camera-retro icon from FontAwesome icon?

Here is the example that shows generating SVG element with font-awesome. As you can see it only works with original unicode. That's why I need to get the original unicode, not the font-awesome one DEMO

I am able to get the FontAwesome unicode with this function:

function faUnicode(name) {
    var testI = document.createElement('i');
    var char;

    testI.className = 'fa ' + name;
    document.body.appendChild(testI);

    char = window.getComputedStyle( testI, ':before' )
        .content.replace(/'|"/g, '');

    testI.remove();
    return char.charCodeAt(0);
}

But as I said, I need to get the original unicode of that icon. Any ideas? Basically in return I want String like '\uf083';

like image 625
Dino Avatar asked Sep 08 '26 05:09

Dino


1 Answers

replace the last line with: return "\\u" + char.charCodeAt(0).toString(16)

like image 145
thedude Avatar answered Sep 10 '26 18:09

thedude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!