A Secure Online Service from Utah.gov

Utah.gov

STAT 2.0

A Service from Utah.gov

STAT.buildtools

Cleanly and easily build DOM elements

Element with Text (no attributes)

stat.build.elementWithText(elementType, displayValue);

Builds a element node with no attributes and some display text.

  • @param {String} elementType
  • @param {String} displayValue
  • @returns {Element}

Example:

stat.build.elementWithText('span', 'foo');

Returns: <span>foo</span>

Element with attributes

stat.build.elementWithAttributes(elementToMake, elementAttributes, displayText);

Generic function that will build an element with optional displayText and add attributes to the element based on the map using the map.key as the attribute name and the map.value as the attributes value

  • @param {string} elementToMake
  • @param {Object} elementAttributes
  • @param {string} displayText
  • @returns {Element}

Example:

stat.build.elementWithAttributes('div', {class: "foo", id: "faa"}, 'bar');

Returns: <div class="foo" id="faa">bar</div>

The above functions only create the elements into the DOM. In order to place them into the view you need to appendChild or use stat.build.putElement() function


Append Created DOM Element to Container

stat.build.putElement(element, container)

Generic function that will append the element as a child to the specified Selector

  • @param {Object} element
  • @param {String OR Object} container

if the 'container' option is a string, document.querySelctor() will be used to find the container

Example:

stat.build.putElement('elementOjbect', 'div.foo');

Build Generic STAT Format Fieldset

This has been moved to: STAT.formbuilder