Slightly better document.createElement
Docrel
is a thin wrapper for document.createElement
that makes creating elements a bit easier. It also helps clean up your code and avoid repetition. No dependencies, no black magic (see source).
Using document.createElement
:
let el = documentelclassName = "wrapper" let input = documentinput let button = documentbuttontextContent = "Submit" if loading button elel
Using docrel
:
let el =
If loading
returns null
the attribute won't be set at all.
Install
npm install docrel --save
Usage
Using createElement
, similarly to document.createElement
:
let el =
<!-- Resulting HTML when el is appended to the DOM --> I'm an HTMLElement!
Using the create
function builder (uses createElement
underneat):
const div = let divOne = let divTwo =
Or just importing the html elements directly:
let divOne = let divTwo =
- The
class
option is a shorthand tonode.className
; - Keys inside
attrs
are passed tonode.setAttribute
, unless key value isnull
orundefined
; - Keys inside
events
are passed tonode.addEventListener
; - Returns an HTML Element object.
Nesting / appending children
The create
/createElement
function supports a third parameter for appending child elements:
let el =
<!-- Resulting HTML when el is appended to the DOM -->
About

This project is sponsored by Heresy. We're always looking for great engineers to join our team, so if you love Elixir, open source and enjoy some challenge, drop us a line and say hello!
Contributing
Contributions are more than welcome. Please fork the repo and send a PR with a clean, rebased branch containing your changes. Also please make sure tests are passing and update tests if necessary.
To run the project locally, you will need to npm install
dev dependencies and then use npm run dev
and npm test
to transpile ES2015 code and run tests, respectively (Node.js >= 6.0 or latest). See package.json
for more info.
Contributors
License
- docrel: LICENSE
- "Heresy" name and logo: Copyright © 2016 Heresy Software Ltd