- newElement([tagName], [...classList]) ⇒
element
Creates an instance of Element.
- newDocument() ⇒
document
Creates an instance of Document. Ran once at setup, creating the exported document variable
- document :
external:document
The document class from jsdom.
- element :
external:element
The element class from jsdom.
newElement([tagName], [...classList]) ⇒ element
Creates an instance of Element.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
[tagName] | string |
"div" |
The tag type. |
[...classList] | string |
Class to apply to element. |
newDocument() ⇒ document
Creates an instance of Document. Ran once at setup, creating the exported document variable
The document class from jsdom.
Kind: global typedef
See: document
- document :
external:document
- .setTitle(title) ⇒
string
- .clearDocument() ⇒
document
- .addJs(function, [...arguments]) ⇒
Element
- .addCss(styles) ⇒
document
- .renderJs([minify]) ⇒
string
|Promise.<string>
- .renderCss([minify]) ⇒
string
- .render() ⇒
string
- .setTitle(title) ⇒
Sets the title of the document.
Kind: instance method of document
Returns: string
- The HTML DOM string of the title element that was put in the document
Param | Type | Description |
---|---|---|
title | string |
Title to apply to the document. |
document.clearDocument() ⇒ document
Replaces the main document with a new one.
Kind: instance method of document
Add a JavaScript snippet to the rendered document. The snippets will only be ran at client. The function must be anonymous where the arguments are the arguments provided in this call. Objects will be JSON stringified while all other argumnets will be stringified with their .toString() method.
Kind: instance method of document
Param | Type |
---|---|
function | function |
[...arguments] | any |
Example (Log "Hello World" to the console)
document.addJs(() => console.log("Hello World"));
Example (Pass local server-side variables)
const num = 5;
document.addJs(n => console.log(n), num);
document.addCss(styles) ⇒ document
Add a CSS snippet to the rendered document. If styles is a string, it will be added to the stylesheet as it is If styles is an object, it will be handled as if every key is a selector with the value as an object where every key is a property with the value as a value.
Kind: instance method of document
Param | Type |
---|---|
styles | object | string |
Example (Usage with string)
element.addCss(`
h1 {
font-size: 2em;
border-radius: 5px;
}
`);
Example (Usage with object)
element.addCss({
"h1": {
"font-size": "2em",
"border-radius": "5px"
}
});
Renders all JavaScript added to the document.
Kind: instance method of document
Returns: string
| Promise.<string>
- the JS code. Returns a {Promise} if minify is true
Param | Type | Default | Description |
---|---|---|---|
[minify] | bool |
false |
If the code should be minified |
Renders all CSS added to the document.
Kind: instance method of document
Returns: string
- the CSS code
Param | Type | Default | Description |
---|---|---|---|
[minify] | bool |
false |
If the code should be minified |
Applies all styles and scripts and returns the HTML string of the document.
Kind: instance method of document
Returns: string
- the HTML page
The element class from jsdom.
Kind: global typedef
See
- element :
external:element
- .addClass(...classList) ⇒
Element
- .setClass(...classList) ⇒
Element
- .removeClass(...classList) ⇒
Element
- .setHTML(html) ⇒
Element
- .addAttribute(name, [value]) ⇒
Element
- .setId(id) ⇒
Element
- .setSrc(src) ⇒
Element
- .setType(type) ⇒
Element
- .setValue(value) ⇒
Element
- .Append(...elements) ⇒
Element
- .Prepend(...elements) ⇒
Element
- .addJs(function, [...arguments]) ⇒
Element
- .addCss(styles) ⇒
Element
- .addClass(...classList) ⇒
Identical to Element.classList.add but returns the {Element}
Kind: instance method of element
See: Element.classList.add
Param | Type | Description |
---|---|---|
...classList | string |
Class to apply to element. |
Adds one or more classes to the element after removing all previous classes.
Kind: instance method of element
Param | Type | Description |
---|---|---|
...classList | string |
Class to apply to element. |
Identical to Element.classList.remove but returns the {Element}
Kind: instance method of element
See: Element.classList.remove
Param | Type | Description |
---|---|---|
...classList | string |
Class to remove from element. |
Identical to Element.innerHTML = html but returns the {Element}
Kind: instance method of element
See: Element.innerHTML = html
Param | Type | Description |
---|---|---|
html | string |
HTML markup to set as the innerHTML of the element |
Identical to Element.setAttribute but returns the {Element}
Kind: instance method of element
See: Element.setAttribute
Param | Type | Default |
---|---|---|
name | string |
|
[value] | string |
"""" |
Identical to Element.id = id but returns the {Element}
Kind: instance method of element
See: Element.id = id
Param | Type |
---|---|
id | string |
Identical to Element.src = src but returns the {Element} and also more reliable
Kind: instance method of element
See: Element.src = src
Param | Type |
---|---|
src | string |
Identical to Element.type = type but returns the {Element} and also more reliable
Kind: instance method of element
See: Element.type = type
Param | Type |
---|---|
type | string |
Identical to Element.value = value but returns the {Element} and also more reliable
Kind: instance method of element
See: Element.value = value
Param | Type |
---|---|
value | string |
Identical to Element.append but returns the {Element}
Kind: instance method of element
See: Element.append
Param | Type |
---|---|
...elements | Element |
Identical to Element.prepend but returns the {Element}
Kind: instance method of element
See: Element.prepend
Param | Type |
---|---|
...elements | Element |
Add a JavaScript snippet to the rendered document. The snippets will only be ran at client. The function must be anonymous where the first argument is the element and the rest is the arguments provided in this call. Objects will be JSON stringified while all other argumnets will be stringified with their .toString() method.
Kind: instance method of element
Param | Type |
---|---|
function | function |
[...arguments] | any |
Example (Log the elements inner text to the console)
element.addJs((el) => console.log(el.innerText));
Example (Pass local server-side variables)
const num = 5;
element.addJs((el, n) => el.innerHTML = n, num);
Add a CSS snippet to the rendered document. If styles is a string, it will be put inside of a declaration block selecting the element If styles is an object, it will be handled as if every key is a property with the value as a value.
Kind: instance method of element
Param | Type |
---|---|
styles | object | string |
Example (Usage with string)
element.addCss(`
font-size: 2em;
border-radius: 5px;
`);
Example (Usage with object)
element.addCss({
"font-size": "2em",
"border-radius": "5px"
});