HtmlBuilder
Builder for generating HTML strings.
- Object
- HtmlBuilder
Remarks
This class is used to generate HTML strings, which are then
converted into HTML DOM nodes using the innerHTML attribute of
an existing DOM node.
Methods
add | Adds a string to the internal buffer. |
addAttribute | Adds an attribute assignment to the internal buffer. |
addCloser | Adds an element closer to the internal buffer. |
addElement | Adds an element with attributes to the internal buffer. |
addEndOpener | Adds '>' to the internal buffer. |
addEventAttribute | Adds an event attribute to the internal buffer. |
addInlineCloser | |
addStartOpener | Adds an element opener to the internal buffer. |
toString | Obtains the built HTML as a string. |
HtmlBuilder add method
Adds a string to the internal buffer.
JavaScript
htmlBuilder.add(string)
Remarks
This adds the specified string to the internal text buffer
used by this HtmlBuilder. The string is not escaped in any way -
if the string contains HTML markup it will be treated as markup.
HtmlBuilder addAttribute method
Adds an attribute assignment to the internal buffer.
JavaScript
htmlBuilder.addAttribute(attributeName,attributeValue)
Remarks
This adds
attributeName, '="', attributeValue, '" '
to
the internal buffer used by this HtmlBuilder.HtmlBuilder addCloser method
Adds an element closer to the internal buffer.
JavaScript
htmlBuilder.addCloser(tagName)
Remarks
This adds
'</', tagName, '>'
to the internal buffer
used by this HtmlBuilder.HtmlBuilder addElement method
Adds an element with attributes to the internal buffer.
JavaScript
htmlBuilder.addElement(name)
Remarks
This is used to add an element and a series of attributes to the HTML.
Example
For example, doing:
htmlBuilder.addElement("div", "class", "foo", "style", "border-width: 10px");
adds <div class="foo" style="border-width: 10px">.
HtmlBuilder addEndOpener method
Adds '>' to the internal buffer.
JavaScript
htmlBuilder.addEndOpener()
Remarks
This adds
'>'
to the internal buffer
used by this HtmlBuilder. See HtmlBuilder.addStartOpener(). HtmlBuilder addEventAttribute method
Adds an event attribute to the internal buffer.
JavaScript
htmlBuilder.addEventAttribute(htmlEventName,ourEventId)
Remarks
This is used to generate attributes for HTML events to call the framework's
event handling mechanism.
Example
For example, doing:
htmlBuilder.addEventAttribute('onclick', ID_click);
adds the necessary wiring for the HTML peer to send 'onclick' events to this controls Control.onPeerEvent() method.
HtmlBuilder addInlineCloser method
JavaScript
htmlBuilder.addInlineCloser()
HtmlBuilder addStartOpener method
Adds an element opener to the internal buffer.
JavaScript
htmlBuilder.addStartOpener(tagName)
Remarks
This adds
'<', tagName, ' '
to the internal buffer
used by this HtmlBuilder. The caller is responsible for adding the finishing
'>' to the buffer by calling HtmlBuilder.addEndOpener(). HtmlBuilder toString method
Obtains the built HTML as a string.
JavaScript
var strVal = htmlBuilder.toString()
Returns
A string containing all the HTML that was added to the builder.