简体   繁体   中英

Bootstrap get glyphicon code

My task is to get code from bootstrap glyphicon element (for example "\\e020").

I've tried the following approach:

html:

<div id="glyph" class="glyphicon glyphicon-trash"></div>

js:

$( document ).ready(function() {
    console.log(window.getComputedStyle($('#glyph')[0], ':before').content);
});

but here I can achieve only the character itself, not the original code.

Is there a way to get the string of "\\e020"?

You can use toString method with 16 parameter to transform char to HEX:

var content = window.getComputedStyle($('#glyph')[0], ':before').content
var result = '\\' + content.charCodeAt(1).toString(16);    
alert(result);

See working example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM