domstyle
v1.0.1
Published
DOM manipulation of the style property
Downloads
4
Maintainers
Readme
domstyle
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'} );