<div>
or <span>
, or any other dom element). dom.asset()
const dom = require('quantum-dom')
// An asset that is loaded from a file
dom.asset({
url: "/resources/lib.js",
filename: 'lib.js'
})
// An anonymous asset that takes a string as the content
dom.asset({
type: "js",
content: 'alert("example")'
})
'js'
or 'css'
. This is required when the url is not provided, otherwise it is ignored. dom.create()
const dom = require('quantum-dom')
const div = dom.create('div')
.class('button-container')
.add(dom.create('button').text('Click me'))
div.stringify()
// '<div class="button-container"><button>Click me</button></div>'
const dom = require('quantum-dom')
const div = dom.create('div')
.add(dom.create('div').class('child-1'))
.add(dom.create('div').class('child-2'))
const dom = require('quantum-dom')
const div = dom.create('div')
.add([
dom.create('div').class('child-1'),
dom.create('div').class('child-2')
])
true
to keep the children at the end of list of children when they are stringified false
const dom = require('quantum-dom')
const div = dom.create('div')
.add(getName().then(name => dom.create('div').text(name)))
.add(getAge().then(age => dom.create('div').text(age)))
true
to keep the child at the end of list of children when it is stringified false
const dom = require('quantum-dom')
const div = dom.create('div')
.attr('class', 'my-div')
div.attr('class') // returns 'my-div'
undefined
if no value is set for the attribute const dom = require('quantum-dom')
const button = dom.create('button')
.class('button outline danger')
div.classed('button') // returns true
div.classed('outline') // returns true
div.classed('positive') // returns false
const dom = require('quantum-dom')
const button = dom.create('button')
.class('button outline danger')
button.classed('button') // returns true
button.classed('button', false)
button.classed('button') // returns false
button.classed('positive', true)
button.class() // returns 'danger outline positive'
button.classed('danger outline', false)
button.class() // returns 'positive'
const dom = require('quantum-dom')
const child1 = dom.create('div').class('child-1')
const child2 = dom.create('div').class('child-1')
const div = dom.create('div')
.add([child1, child2])
child1.remove()
// 'div' just has child2 as a child now
const dom = require('quantum-dom')
const child1 = dom.create('div')
const child2 = dom.create('div')
const div = dom.create('div')
.add([child1, child2])
div.removeChild(child1)
// 'div' just has child2 as a child now
const dom = require('quantum-dom')
const div = dom.create('div')
.add(dom.create('div').class('child-1'))
.add(dom.create('div').class('child-2'))
div.stringify()
// <div><div class="child-1></div><div class="child-2></div></div>
const dom = require('quantum-dom')
const div = dom.create('div')
.text("Some text")
head()
. Instances of this should be created only using the head()
function. bodyClassed
function. bodyClassed
function uses type 'body-classed'
textNode
factory function. const dom = require('quantum-dom')
dom.create('div')
.add(dom.textNode('hello'))
// Add html to the page without converting < to < etc.
.add(dom.textNode('<div id="my-div"></div>', { escape: false }))
const dom = require('quantum-dom')
// An asset that is loaded from a file
dom.asset({
url: "/resources/lib.js",
filename: 'lib.js'
})
// An anonymous asset that takes a string as the content
dom.asset({
type: "js",
content: 'alert("example")'
})
'js'
or 'css'
. This is required when the url is not provided, otherwise it is ignored. const dom = require('quantum-dom')
// Adds the class '.extra-body-class' to the body
const extraBodyClass = dom.bodyClassed('extra-body-class', true)
const div = dom.create('div')
dom.stringify([
extraBodyClass,
div
])
/* Returns a promise with:
{
html: '<!DOCTYPE html>\n<html>\n<head></head>\n<body class="qm-body-font extra-body-class"><div></div></body></html>',
assets: []
}
*/
dom.create('div')
not dom.create('DIV')
). No validation is performed on the type, so custom elements can also be created. const dom = require('quantum-dom')
const div = dom.create('div') // Creates a <div> element
const span = dom.create('span') // Creates a <span> element
const button = dom.create('button') // Creates a <button> element
const myElement = dom.create('myElement') // Creates a <myElement> custom element
<head>
of the page when the virtual dom is converted to html const dom = require('quantum-dom')
const root = dom.create('div')
.add(dom.create('div').class('my-element'))
.add(dom.head(dom.create('style').text('.my-element { background: red; }', {escape: false})))
const dom = require('quantum-dom')
dom.randomId() // returns a new random id
const dom = require('quantum-dom')
const div = dom.create('div').class('button-container').add(dom.create('button').text('Click me'))
dom.stringify([div])
{
html: '<!DOCTYPE html>\n<html>\n<head></head>\n<body class="qm-body-font"><div class="button-container"><button>Click me</button></div></body></html>',
assets: []
}
assetPath
destination. https://username.github.io/project
the baseUrl
would be "/project"
true
const dom = require('quantum-dom')
dom.create('div')
.add(dom.textNode('hello'))
.add(dom.textNode('<div id="my-div"></div>', {escape: false}))
true
const dom = require('quantum-dom')
// Creates a <div></div> element
dom.create('div')
// Creates a <div id="my-id"></div> element
dom.create('div').id('my-id')
// Creates a <a href="/link/to/somewhere">Link</a> element
dom.create('a').attr('href', '/link-to-somewhere').text('Link')
// Creates a <span class="my-class"></span> element
dom.create('span').class('my-class')
// Creates an element that will render out to <h1>My Header</h1>
dom.create('h1').text('My Header')
/*
Creates the following dom structure:
<div class="outer-div">
<div class="inner-div"></div>
</div>
*/
dom.create('div').class('outer-div')
.add(dom.create('div').class('inner-div'))