Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

element-creator

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

element-creator

A javascript library that helps creating html elements easily. Inspired by mithriljs framework.

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

element-creator Build Status size npm version License: MIT

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


<script  type="text/javascript" src="https://unpkg.com/element-creator@1.0.5/build/element-creator.min.js"></script>

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');
import e from 'element-creator';

var myDiv = e('div#myElement.class__1[name=awesome-div]', 'My awesome div', {
    on: { 'click': function(e) {
        alert('You have clicked on My awesome div');
    }}
})

The variable myDiv above generates div html element with click event that prop an alert message.

<div id="myElement" class="class__1" name="awesome-div">My awesome div</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 element
var vdom = e(elementString, children, options)

Where:

  • elementString is a string that specify the element parameters creation with following pattern:

{elementType}{(*)elementId}{(*)elementClasses}{(*)elementAttributes}

(*) is optional

ParametersDefaultDescriptionExample
elementTypedivType of element or element's tag typep or h1. Use default incase left empty
elementIdElement's id#firstParagraph
elementClassesElement classes.class__1 or multiple classes .class__1.class_2
elementAtrributesElement 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 functions
var wrappedElement = e.wrap(querySelector, isMultiple)

Where:

  • querySelector is standard query selector string for example h1 will look for heading h1, .class__1 will look for any element has class .class__1.
  • isMultiple is false by default. If set to true it will return an array of element match with querySelector.

Keywords

FAQs

Package last updated on 04 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc