BetterElement Build Codecov Docs

Create your own elements through client-side JavaScript.

Installation

npm i betterelement
# or, with Yarn,
yarn add betterelement

Usage

// First, create a new Element.
var element = new Element('hello');
// Then, let's add a toExecuteOnRead.
element.toExecuteOnRead = function (index, element) {
    element.innerHTML = 'hello';
    if (Math.random() < 0.51) {
        element.innerHTML += ' world!';
    } else {
        element.innerHTML += ' death!';
    }
}
// Now, let's build.
element.readElements();
...
<body>
    <h1><hello></hello></h1>
    <p>
        ...
    </p>
    ...
</body>
...

Results in:

...
<body>
    <h1><hello>Hello, death!</hello></h1>
    <p>
        ...
    </p>
    ...
</body>
...

For more examples, see doClock and doRandom in betterelement.js. Here it is in action!