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

domjs

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

domjs

Build dom structure easy way with plain js. Client and server side template engine

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

domjs - Client and server side dom template engine

Build dom structure easy way with plain JavaScript.
Can be used on both client and server side.
Due to its small footprint it suits small projects best.

Instalation

When using node:

$ npm install domjs

Instructions for browser side installation coming soon.

Usage

What would be the easiest, most intuitive way to build html5 DOM tree with
plain JavaScript ?

var mytemplate = function () {
	header(
		h1('Heading'),
		h2('Subheading'));

	nav(
		ul({ class: 'breadcrumbs' },
			li(a({ href: '/' }, 'Home')),
			li(a({ href: '/section/'}, 'Section')),
			li(a('Subject'))));

	article(
		p('Lorem ipsum...'));

	footer('Footer stuff');
};

This is how templates for domjs are written. To get mytemplate function
content turned into DOM (literally DocumentFragment):

var domjs = require('domjs/lib/html5')(document);

var mydom = domjs(mytemplate);

Other notes

You can save references to elements and operate on them later:

var myul = ul(li('one'), li('two'), li('three'));

// ... some code ...

// add extra items to myul
myul(li('four'), li('five));

// append myul into other element
div(myul);

You can access DOM elements directly, just invoke returned function with no
arguments

(myul() instanceof DOMElement) === true

Comment type nodes:

_comment('my comment');

CDATA type nodes

_cdata('cdata text');

Text nodes in main scope:

_text('my text');

Elements with names that are reserved keywords in JavaScript language,
like 'var', should be created with preceding underscore added to its name:

_var('var content');

Tests

When installed for node with npm (do make install first)

$ make test

Tests with coverage report:

$ make test-cov

Keywords

FAQs

Package last updated on 29 May 2011

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