javascript - Programmatically get FontAwesome unicode value by name -
following steps outlined in this answer, setting cursor fontawesome icon. now, set cursor icon, class name (for example, fa-pencil
). accomplish this, seems need able programmatically lookup unicode value of given icon.
i know these values listed in font-awesome.css
stylesheet, avoid parsing file, if method exists.
is possible?
possibly late, allow this: elt.innerhtml = faunicode('pencil');
maybe can else searching same thing.
function faunicode(name) {'use strict'; // create holding element (they tend use <i>, let's that) const testi = document.createelement('i'); // create realistic classname // - maybe 1 day need both, let's add them testi.classname = `fa fa-${name}`; // need append body have // pseudo element created document.body.appendchild(testi); // computed style const char = window.getcomputedstyle( testi, ':before' // add ':before' pseudo element ).content.replace(/'|"/g, ''); // content wraps things in quotes // don't want // remove test element testi.remove(); return char.charcodeat(0); }
or in ecma5:
function faunicode(name) { var testi = document.createelement('i'); var char; testi.classname = 'fa fa-' + name; document.body.appendchild(testi); char = window.getcomputedstyle( testi, ':before' ) .content.replace(/'|"/g, ''); testi.remove(); return char.charcodeat(0); }
Comments
Post a Comment