domstyle

1.0.1 • Public • Published

domstyle Build Status NPM version

DOM manipulation of the style property

Installation

$ npm install --save domstyle

Examples

Node

var domstyle = require('domstyle')(document);
 
...
 
domstyle('.first').set( {color: 'black', background: 'red'} )
domstyle('.first').get('color', 'background');
 

Client side

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>domstyle</title>
    <script src="domstyle.js"></script>
</head>
<body>
 
<p id="helloWorldId">Hello World!</p>
 
<script>
    var domstyle = domstyle(document);
 
    domstyle('body').set( {background: 'black'} );
    domstyle('body p').set( {color: 'white', 'font-size': '25px'} );
    console.log( domstyle('body')('#helloWorldId').get('color') ); // {color: "white"}
    console.log( domstyle('#helloWorldId').get('font-size') );     // {font-size: "25px"}
</script>
</body>
</html>

Methods

Get

Syntax
domstyle(selectors).get(attr1[, attr2, ...]);
  • attr1, attr2 - style attributes.
Example
domstyle('.className').get('color', 'font-size'); // result: { color: ..., font-size: ... }

Set

Syntax
domstyle(selectors).set( {attr1: value1[, attr2: value2, ...]} );
  • attr1, attr2 - style attributes;
  • value1, value2 - new values of the attributes.
Example
domstyle(selectors).set( {color: 'red', background: 'black'} );

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i domstyle

    Weekly Downloads

    2

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • ivandyachenko