A tiny framework to write easily HTML code in javascript
- Download the latest release.
- Clone the repo:
git clone https://github.com/jccazeaux/scriber.git
. - Install with npm:
npm install scriber-js
.
scriber
.div()
.id("myId")
.class("my-css-class")
.input()
.value("my value")
.end()
.element("span")
.class("red")
.end()
.end()
.toString
Produces
<div id="myId" class="my-css-class"><input value="my value"><span style="red"></span></div>
Creates the root element. You can use generic "element" function with will take the tagName as parameter, or a shortcut function wich name will be the tagName.
This function will return an "Element" object to work on the new created element
Creates a child element with same rules.
This function returns the created element. To close this element, use the end function.
Ends the current element. Returns the parent element.
Creates an attribute on the element. You can use either a shortcut function or generic element() function
Adds a text node. No need to end a text node as it does not accept children.
Return the element as a String
Return the element as HTMLElement object
Scriber supports shortcuts for the following tags
["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","big","blockquote","body",
"br","button","canvas","caption","center","cite","code","col","colgroup","datalist","dd","del","details","dfn","dialog","dir","div",
"dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1",- "h6","head","header","hr",
"html","i","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","menu","menuitem","meta",
"meter","nav","noframes","noscript","object","ol","optgroup","option","output","p","param","pre","progress","q","rp","rt","ruby",
"s","samp","script","section","select","small","source","span","strike","strong","style","sub","summary","sup","table","tbody",
"td","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr"]
Scriber supports shortcuts for the following attributes. The style attribute has no shortcut because the style method already handles the style tag. If you really want to add a style attribute (instead of class), use the generic attr("style") method.
["alt", "diabled", "href", "src", "title", "value", "name", "id", "class"]
``