dom-create-element
Create DOM elements.
Usage
npm install dom-create-element
var create = ; var el = ; documentbody;
Available options:
selector
: the string type tag of the HTML element (required)id
: unique ID selector of the elementstyles
: CSS classes of the element (this is not inline styles)attr
: custom attributeslink
: ifselector
is a<a>
element, provide ahref
(required)target
: ifselector
is a<a>
element, you can define targetsrc
: ifselector
is an<img>
element, provide asrc
lazyload
: ifselector
is an<img>
element, you can definelazyload
(see below)html
: the content of the element (basically innerHTML)children
: the children of the element. could be another instance ofcreate
so you could chain element creation
For images, you can pass lazyload: true
.
This will set the image to opacity: 0
, then go back to 1
when it's loaded.
var image = ;
TODOs
- lazyload for images
- cleaner options:
opt
should first be the selector with more options as second parameter - tests
License
MIT, see LICENSE.md for details.