Skip to content

Pass in an element and get an object with the element and the font related styles inside an array

License

Notifications You must be signed in to change notification settings

HitFox/get-font-styles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'}
      ]
    }
  */

About

Pass in an element and get an object with the element and the font related styles inside an array

Resources

License

Stars

Watchers

Forks

Packages

No packages published