https://github.com/goto-bus-stop/append-children
Append things to a DOM element.
https://github.com/goto-bus-stop/append-children
Last synced: 4 months ago
JSON representation
Append things to a DOM element.
- Host: GitHub
- URL: https://github.com/goto-bus-stop/append-children
- Owner: goto-bus-stop
- License: mit
- Created: 2017-05-13T10:57:52.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-01-30T07:13:10.000Z (5 months ago)
- Last Synced: 2025-03-01T01:12:20.411Z (4 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# append-children
Append children to a DOM element, like [Element.append](https://developer.mozilla.org/en-US/docs/Web/API/Element/append) for very old browsers.
## Install
With npm do:
```
npm install --save append-children
```## Usage
```js
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](./LICENSE)