src/basis/dom.js
function createElement(config){
    var isConfig = config != undefined && typeof config != 'string';
    var description = (isConfig ? config.description : config) || '';

    var elementName = 'div'; // modern browsers become case sensetive for tag names for xhtml
    var element;

    // fetch tag name
    var m = description.match(/^([a-z0-9_\-]+)(.*)$/i);
    if (m)
    {
      elementName = m[1];
      description = m[2];
    }

    // create an element

    if (description != '')
    {
      // extract properties
      var classNames = [];
      var attributes = {};
      var entryName;

      while (m = DESCRIPTION_PART_REGEXP.exec(description))
      {
        if (m[8])
        {
          throw new Error(
            'Create element error in basis.dom.createElement()' +
            '\n\nDescription:\n> ' + description +
            '\n\nProblem place:\n> ' + description.substr(0, m.index) + '-->' + description.substr(m.index) + '<--'
          );
        }

        entryName = m[1] || m[2] || m[3];

        if (m[1])     // id
          attributes.id = entryName;
        else
          if (m[2])   // class
            classNames.push(entryName);
          else
          {           // attribute
            if (entryName != 'class')
              attributes[entryName] = m[4] ? m[5] || m[6] || m[7] || '' : entryName;
          }
      }

      // create element
      if (IS_ATTRIBUTE_BUG_NAME && attributes.name && /^(input|textarea|select)$/i.test(elementName))
        elementName = '<' + elementName + ' name=' + attributes.name + '>';
    }

    // create element
    element = document.createElement(elementName);

    // set attributes
    if (attributes)
    {
      if (attributes.style && IS_ATTRIBUTE_BUG_STYLE)
        element.style.cssText = attributes.style;

      for (var attrName in attributes)
        element.setAttribute(attrName, attributes[attrName], 0);
    }

    // set css classes
    if (classNames && classNames.length)
      element.className = classNames.join(' ');

    // append child nodes
    if (arguments.length > 1)
      handleInsert(element, createFragment.apply(0, basis.array.flatten(arrayFrom(arguments, 1))));

    // attach event handlers
    if (isConfig)
    {
      if (config.css)
      {
        if (!cssom)
          cssom = require('basis.cssom');
        cssom.setStyle(element, config.css);
      }

      for (var event in config)
        if (typeof config[event] == 'function')
          eventUtils.addHandler(element, event, config[event], element);
    }

    // return an element
    return element;
  }
function createElement(config){
    var isConfig = config != undefined && typeof config != 'string';
    var description = (isConfig ? config.description : config) || '';

    var elementName = 'div'; // modern browsers become case sensetive for tag names for xhtml
    var element;

    // fetch tag name
    var m = description.match(/^([a-z0-9_\-]+)(.*)$/i);
    if (m)
    {
      elementName = m[1];
      description = m[2];
    }

    // create an element

    if (description != '')
    {
      // extract properties
      var classNames = [];
      var attributes = {};
      var entryName;

      while (m = DESCRIPTION_PART_REGEXP.exec(description))
      {
        if (m[8])
        {
          throw new Error(
            'Create element error in basis.dom.createElement()' +
            '\n\nDescription:\n> ' + description +
            '\n\nProblem place:\n> ' + description.substr(0, m.index) + '-->' + description.substr(m.index) + '<--'
          );
        }

        entryName = m[1] || m[2] || m[3];

        if (m[1])     // id
          attributes.id = entryName;
        else
          if (m[2])   // class
            classNames.push(entryName);
          else
          {           // attribute
            if (entryName != 'class')
              attributes[entryName] = m[4] ? m[5] || m[6] || m[7] || '' : entryName;
          }
      }

      // create element
      if (IS_ATTRIBUTE_BUG_NAME && attributes.name && /^(input|textarea|select)$/i.test(elementName))
        elementName = '<' + elementName + ' name=' + attributes.name + '>';
    }

    // create element
    element = document.createElement(elementName);

    // set attributes
    if (attributes)
    {
      if (attributes.style && IS_ATTRIBUTE_BUG_STYLE)
        element.style.cssText = attributes.style;

      for (var attrName in attributes)
        element.setAttribute(attrName, attributes[attrName], 0);
    }

    // set css classes
    if (classNames && classNames.length)
      element.className = classNames.join(' ');

    // append child nodes
    if (arguments.length > 1)
      handleInsert(element, createFragment.apply(0, basis.array.flatten(arrayFrom(arguments, 1))));

    // attach event handlers
    if (isConfig)
    {
      if (config.css)
      {
        if (!cssom)
          cssom = require('basis.cssom');
        cssom.setStyle(element, config.css);
      }

      for (var event in config)
        if (typeof config[event] == 'function')
          eventUtils.addHandler(element, event, config[event], element);
    }

    // return an element
    return element;
  }
function createElement ( config ) { var isConfig = config != undefined && typeof config != 'string' ; var description = ( isConfig ? config . description : config ) || '' ; var elementName = 'div' ; // modern browsers become case sensetive for tag names for xhtml var element ; // fetch tag name var m = description . match ( / ^([a-z0-9_\-]+)(.*)$ / i ) ; if ( m ) { elementName = m [ 1 ] ; description = m [ 2 ] ; } // create an element if ( description != '' ) { // extract properties var classNames = [ ] ; var attributes = { } ; var entryName ; while ( m = DESCRIPTION_PART_REGEXP . exec ( description ) ) { if ( m [ 8 ] ) { throw new Error ( 'Create element error in basis.dom.createElement()' + '\n\nDescription:\n> ' + description + '\n\nProblem place:\n> ' + description . substr ( 0 , m . index ) + '-->' + description . substr ( m . index ) + '<--' ) ; } entryName = m [ 1 ] || m [ 2 ] || m [ 3 ] ; if ( m [ 1 ] ) // id attributes . id = entryName ; else if ( m [ 2 ] ) // class classNames . push ( entryName ) ; else { // attribute if ( entryName != 'class' ) attributes [ entryName ] = m [ 4 ] ? m [ 5 ] || m [ 6 ] || m [ 7 ] || '' : entryName ; } } // create element if ( IS_ATTRIBUTE_BUG_NAME && attributes . name && / ^(input|textarea|select)$ / i . test ( elementName ) ) elementName = '<' + elementName + ' name=' + attributes . name + '>' ; } // create element element = document . createElement ( elementName ) ; // set attributes if ( attributes ) { if ( attributes . style && IS_ATTRIBUTE_BUG_STYLE ) element . style . cssText = attributes . style ; for ( var attrName in attributes ) element . setAttribute ( attrName , attributes [ attrName ] , 0 ) ; } // set css classes if ( classNames && classNames . length ) element . className = classNames . join ( ' ' ) ; // append child nodes if ( arguments . length > 1 ) handleInsert ( element , createFragment . apply ( 0 , basis . array . flatten ( arrayFrom ( arguments , 1 ) ) ) ) ; // attach event handlers if ( isConfig ) { if ( config . css ) { if ( ! cssom ) cssom = require ( 'basis.cssom' ) ; cssom . setStyle ( element , config . css ) ; } for ( var event in config ) if ( typeof config [ event ] == 'function' ) eventUtils . addHandler ( element , event , config [ event ] , element ) ; } // return an element return element ; }
Creates a new Element with arguments as childs.
@param {string|object} config CSS-selector like definition or object for extended Element creation.
@param {...Node|object} children Child nodes
@return {!Element} The new Element.
Creates a new Element with arguments as childs .