Utility function for creating a node - Node.js DOM

Node.js examples for DOM:Node

Description

Utility function for creating a node

Demo Code


/**/*  w  w  w  .  ja v  a 2s .  c om*/
 * Utility function for creating a node
 * @param namespace
 * @param tag
 * @param attName
 * @param attValue
 * @param text
 * @return - created node
 */
function createNodeStructure(namespace, tag, attName, attValue, text) {
  var n = document.createElementNS(namespace, tag);
  if (attName != null && attValue != null) {
    n.setAttribute(attName, attValue);
  }
  if (text != null) {
    n.appendChild(document.createTextNode(text));
  }
  return n;
}

Related Tutorials