Inline-Styler
Inline-Styler is a teeny tiny JavaScript library to easily manipulate the style
attribute of an element.
It also works seamlessly with Cheerio on the server-side as well.
API
.hasStyle(property)
Check whether the element has property
set in its style
attribute.
// <div style="color: red;">…</div>var styler = nodevar hasColor = styler // truevar hasFontSize = styler // false
.getStyle(property)
Get value of property
set in its style
attribute or null
.
// <div style="color: red;">…</div>var styler = nodevar color = styler // redvar fontSize = styler // null
.unsetStyle(property)
Unset property
from style
attribute.
var styler = nodestyler
.setStyle(property, value)
Set property
to value
in style
attribute. Override style if it already exists.
var styler = node // Individualstylerstyler // Chainedstyler
.setStyles(object)
Alias for .setStyle(object)
.
var styler = node styler
.toString()
Returns the string representation to be set as style
attribute.
// <div style="color: red;">…</div>var styler = nodestylernode// <div style="color: blue;">…</div>
Options
var styler = node spaceAfterColon: false spaceAfterSemiColon: false trailingSemiColon: falsestylerstylernode// <div style="color:blue;background:red">…</div>
Tests
npm test