tag-builder
Fluent html tag building library.
Install
npm install --save tag-builder
Examples
const assert =const TagBuilder =const div = 'div'const html = divtext'hello world'assert
const html = TagBuilderassert
const ul = TagBuilderconst li1 = TagBuildertext'1'const li2 = TagBuildertext'2'ululconst html = ulassert
See tests for more examples.
API
All methods except toString()
return a TagBuilder instance and are chainable.
create(tagName: string)
Returns a TagBuilder instance.
html(html: any)
Sets innerHTML of the element. You may pass either a string or TagBuilder instance to this method.
appendHtml(html: any)
Appends provided html to inner content. You may pass either a string or TagBuilder instance to this method.
text(text: string)
Sets html encoded innerText of the element.
appendText(text: string)
Appends html encoded text to inner content.
attr(attributes: object)
Merges attributes hash onto the tag.
addClass(className: string)
Merges className onto the tag.
toString()
Returns html string.