append-children
Append things to a DOM element.
Last updated 4 years ago by goto-bus-stop .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install append-children 
SYNC missed versions from official npm registry.

append-children

Append children to a DOM element.

Install

With npm do:

npm install --save append-children

Usage

var appendChildren = require('append-children')
var element = document.createElement('div')

// append a single thing
appendChildren(element, document.createElement('p'))

// append multiple things
appendChildren(element, [
  // other DOM elements
  document.createElement('span'),
  // strings and friends
  'hello world',
  123,
  /regexes/gi,
  new Date(),
  // nested arrays of things to append
  [[[someOtherElement()]]]
])

function someOtherElement() {
  var hello = document.createElement('span')
  appendChildren(hello, 'hello')
  var world = document.createElement('strong')
  appendChildren(world, 'world')
  return [hello, ' ', world]
}

API

appendChildren(element, child)

Append a DOM element child to another DOM element element.

appendChildren(element, str)

Append a string str to a DOM element element. A Text node will be created to contain the string. RegExps, Dates and Numbers are converted to a string using toString().

appendChildren(element, arr)

Append multiple things to a DOM element element. arr can be an array of any of the things accepted by the other forms.

License

MIT

Current Tags

  • 1.0.0                                ...           latest (4 years ago)

1 Versions

  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |