The goal of domali is to provide a more readable DOM API while keeping the core functionality intact. You can use all of the native JavaScript DOM functions and objects with domali.
import dom from 'domali'
const [ foo, bar, baz ] = dom.getId('foo', 'bar', 'baz')
console.log(foo, bar, baz)
Load domali through a module loader for the browser. Popular choices for module loading include webpack, jspm, and browserify. Destructuring requires ES6.
const foo = dom.getId('foo')
const [ foo, bar, baz ] = dom.getId('foo', 'bar', 'baz')
const bar = dom.getClass('bar')
const divs = dom.getTags('div')
const foo = dom.select('#foo')
const baz = dom.selectAll('.baz')
const div = dom.create('div')
console.log(div === '<div></div>') // true
const [ p, a, img ] = dom.create('p', 'a', 'img')
console.log(p === '<p></p>') // true
console.log(a === '<a></a>') // true
console.log(img === '<img></img>') // true
const div = dom.create('div').text('hey')
const newDiv = dom.clone(div)
console.log(newDiv) // <div>hey</div>
const div = dom.create('div').text('Hello, domali!')
dom.render(div)
dom.clear()
const div = dom.create('div').text('hello')
console.log(div.textContent === 'hello') // true
const div = dom.create('div')
div.push(dom.create('div'))
div.push(dom.create('i'))
div.push(dom.create('span'))
console.log(div.firstChild === '<div></div>') // true
const div = dom.create('div')
div.unshift(dom.create('div'))
div.unshift(dom.create('i'))
div.unshift(dom.create('span'))
console.log(div.firstChild === '<span></span>') // true
const rootDiv = dom.create('div')
rootDiv.push(dom.create('div'))
rootDiv.push(dom.create('div'))
rootDiv.push(dom.create('div'))
const newDiv = rootDiv.map(div => {
console.log(div) // <div></div>
return dom.create('a')
})
console.log(newDiv)
// <div>
// <a></a>
// <a></a>
// <a></a>
// </div>
const div = dom
.create('div')
.set({ id: 'foo' })
console.log(div) // <div id="foo"></div>
const divId = dom
.create('div')
.set({ id: 'foo' })
.get('id')
console.log(divId) // foo
const a = dom
.create('a')
.set({
id: 'my-link',
href: 'https://google.com',
class: 'link'
})
console.log(a) // <a id="my-link" href="https://google.com" class="link"></a>
const [imgId, imgSrc, imgClass] = dom
.create('img')
.set({
id: 'my-image',
src: 'some-image.png',
class: 'photo'
})
.get('id', 'src', 'class')
console.log(imgId) // my-image
console.log(imgSrc) // some-image.png
console.log(imgClass) // photo