Socket
Book a DemoInstallSign in
Socket

htmele

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmele

Programatically create html elements

latest
Source
npmnpm
Version
1.0.12
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

HTMeLe

Programatically create HTMElements

Usage

npm install htmele
var htmele = require('htmele');
var element = htmele.create(tag <string>[, content <string|array>, attributes <object>]); //creates standard html tag <tag attr1=val1 attr2=val2>content</tag>

Example

var mydiv = htmele.create(
	'div',
	htmele.create(
		'a',
		[
			htmele.create('img', {src: "click-here-image.jpg"}),
			'Click Here'
		],
		{
			href: "http://google.com"
		}
	),
	{
		style: "color: #fff; width: 200px;"
	}
);

console.log(mydiv); //<div style="color: #fff; width: 200px;"><a href="http://google.com"><img src="click-here-images.jpg" /> Click Here</a></div>

More Info

HTMEle will autmatically determine whether or not to use a full html block or short tag based on the tag string you pass to it. If you want to see a list of which tags are treated as "short" you can see an array by calling the following method:

console.log(htmele.getShortTags());

Short tags do not accept any content so the second argument is treated as attributes. Take the following example to differentiate:

// Standard HTML Block tag <div>
console.log(htmele.create('div', ['foo', 'bar'], {style: "background: #eee;"})); //<div style="background: #eee;">foo bar</div>

// Short HTML tag <img>
console.log(htmele.create('img', {src: "my-image.jpg"})); //<img src="my-image.jpg">

Keywords

html

FAQs

Package last updated on 03 Dec 2016

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