mak

makeelement

A function to use it instead of document.createElement

Showing:

Popularity

Downloads/wk

2

GitHub Stars

2

Maintenance

Last Commit

2yrs ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

0.4KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

makeElement npm version Build Status

Compact, fast, dependency-free function to use instead of document.createElement

npm install --save makeelement
const makeElement = require('makeelement');

It also creates a global variable makeElement in non-CJS environment.

<script src="makeelement.js"></script>
<script>
const element = makeElement('div');
</script>

Usage

makeElement accepts a tag name and its properties or properties object only which can include tagName property (div by default).

const element = makeElement('div', {
    className: 'foo',
    hidden: false
});
const element = makeElement({
    tagName: 'div'
    className: 'foo',
    hidden: false
});

The function also allows to define attributes, children, style and dataset simultaneously. children, in their turn, may include their own children and its item can also be a DOM node.

const element = makeElement('div', {
    attributes: {
        foo: 'a',
        bar: 'b'
    },
    children: [{
        tagName: 'div',
        className: 'child-1'
    }, {
        tagName: 'div',
        className: 'child-2',
        children: [{
          tagName: 'div',
          className: 'grand-child',
          children: [{
            tagName: 'div',
            className: 'grand-grand-child',
          }]
        }]
    }],
    dataset: {
        foo: 'a',
        bar: 'b'
    },
    style: {
        position: 'absolute',
        backgroundColor: 'red'
    }
});

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100