Use this instead of the "Hello World" below:
[...document.getElementsByTagName('hello')].map(element => {
element.innerHTML = 'hello';
if (Math.random() < 0.51) {
element.innerHTML += ' world!';
} else {
element.innerHTML += ' death!';
}
});
No library needed!
(For ES3, use a for loop instead.)
Create your own elements through client-side JavaScript.
npm i betterelement
# or, with Yarn,
yarn add betterelement
// 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!