The htmlBuilder interface is used create HTML markup. It makes it easy to generate markup that is well-formed and properly escaped. It is simpler and safer than using string concatenation and doesn't require the overhead of using a template library. For simple templates see apex.util.applyTemplate
Example
var out = apex.util.htmlBuilder();
out.markup( "<label" )
.attr( "for", options.id )
.markup( ">" )
.content( option.label )
.markup( "</label><input type='text'" )
.attr( "id", options.id )
.attr( "class", "specialInput" )
.optionalAttr( "title", options.title )
.attr( "size", options.size )
.attr( "maxlength", options.maxChars )
.attr( "value", "" )
.markup( " />" );
$( "#myContainer", out.toString() );
Add an attribute.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pName |
string |
<optional> |
Attribute name. A leading space and trailing = is added and the value is quoted. If not given just the value is added without being quoted. |
pValue |
string | Attribute value. This will be escaped. |
Returns:
This htmlBuilder instance for method chaining.
- Type
- this
Remove all markup from this builder interface instance. Use this when you want to reuse the builder instance for new markup.
Add element content. The content is escaped.
Parameters:
Name | Type | Description |
---|---|---|
pContent |
string | The content to add between an element open and closing tags. |
Returns:
This htmlBuilder instance for method chaining.
- Type
- this
Add markup.
Parameters:
Name | Type | Description |
---|---|---|
pMarkup |
string | The markup to add. No escaping is done. |
Returns:
This htmlBuilder instance for method chaining.
- Type
- this
Add an optional attribute. The attribute and its value is only added if the value is a non-empty string or a non-zero number or true.
Parameters:
Name | Type | Description |
---|---|---|
pName |
string | Attribute name. A leading space and trailing = is added and the value is quoted. |
pValue |
string | Attribute value. This will be escaped. |
Returns:
This htmlBuilder instance for method chaining.
- Type
- this
Add an optional Boolean attribute. The attribute is added only if the value is true.
Parameters:
Name | Type | Description |
---|---|---|
pName |
string | Attribute name. A leading space is added. |
pValue |
boolean | If true the attribute is added. If false the attribute is not added. |
Returns:
This htmlBuilder instance for method chaining.
- Type
- this
Return the HTML markup.
Returns:
The markup that has been built so far.
- Type
- string