Giter Club home page Giter Club logo

dom-create-element's Introduction

dom-create-element

stable

Create DOM elements.

Usage

npm install dom-create-element

var create = require('dom-create-element');

var el = create({
  selector: 'div',
  id: 'el-id',
  styles: 'el-classes',
  children: create({
  	selector: 'a',
  	link: 'http://google.com',
  	target: '_blank',
  	html: 'Link'
  })
});

document.body.appendChild(el);

Available options:

  • selector: the string type tag of the HTML element (required)
  • id: unique ID selector of the element
  • styles: CSS classes of the element (this is not inline styles)
  • attr: custom attributes
  • link: if selector is a <a> element, provide a href (required)
  • target: if selector is a <a> element, you can define target
  • src: if selector is an <img> element, provide a src
  • lazyload: if selector is an <img> element, you can define lazyload (see below)
  • html: the content of the element (basically innerHTML)
  • children: the children of the element. could be another instance of create 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 = create({
  selector: 'img',
  src: '/path/to/img.jpg',
  lazyload: true
});

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.