element-creator
A library that helps to create interactive HTML elements (virtual dom) easily. Inspired by MithrilJs framework.
Installation
element-creator is available on NPM and as a Javascript library.
Install on NPM
npm install element-creator
Or include on html file on unpkg
Examples:
A one page content example located at build/index.html
. Or a quick demo below
// using node with es6, otherwise var e = require('element-creator');; var myDiv =
The variable myDiv
above generates div
html element with click
event that prop an alert message.
My awesome div
Documentation
element-creator contains Elementextended (or wrapper) which wraps/adds interactive functions such as .find, .all to standard element and ElementCreator which creates HTML elements then wrap and return an ElementExtended element.
ElementCreator
// vdom return new elementvar vdom =
Where:
- elementString is a string that specify the element parameters creation with following pattern:
{elementType}{(*)elementId}{(*)elementClasses}{(*)elementAttributes}
(*) is optional
Parameters | Default | Description | Example |
---|---|---|---|
elementType | div | Type of element or element's tag type | p or h1 . Use default incase left empty |
elementId | Element's id | #firstParagraph |
|
elementClasses | Element classes | .class__1 or multiple classes .class__1.class_2 |
|
elementAtrributes | Element attributes | [name=title] or multiple attributes [name=title,ref=titleRef] |
-
children is text node or html elements that stay inside the element.
-
options os other configuration including:
- on: add event listener
- attrs: element's attributes
- data: element's data
ElementExtended
// wrappedElement return a html element within the html body with more interactive functionsvar wrappedElement = e
Where:
- querySelector is standard query selector string for example
h1
will look for headingh1
,.class__1
will look for any element has class.class__1
. - isMultiple is
false
by default. If set totrue
it will return an array of element match with querySelector.