get-font-styles
v1.0.2
Published
Pass in an element and get an object with the element and the font related styles inside an array
Downloads
4
Readme
get-font-styles
This is a tiny module that takes a DOM element as input and returns an object
with that element and a styles
array with the following properties:
font-family
, font-size
, font-weight
, font-style
.
Basic usage
var getFontStyles = require('get-font-styles');
getFontStyles(element);
More Realistic Usage
document.addEventListener('click', function(e) {
e = e || window.event;
var target = e.target || e.srcElement;
var elementWithStyles = getFontStyles(target);
console.log(elementWithStyles);
});
/*
{ element: <div id="test1" style="font-family: Helvetica; font-size: 16px; font-weight: 400; font-style: normal;"></div>,
styles: [
{'font-family': 'Helvetica'},
{'font-size': '16px'},
{'font-weight': '400'},
{'font-style': 'normal'}
]
}
*/