Documentation

BX.create

DOMNode 
BX.create(
 tag[,
 data[,
 context]]
);
or
DOMNode 
BX.create(
 data[,
 context]
);

Creates a DOM structure node. Allows to "attach" events to the node when creating it.

Function parameters

Parameter Description
tag String with the tagName of the node. If not specified (first parameter - object), then the tag name shall be included into the tag property of the data descriptive object.
data Descriptive object, can have the following fields:
  • tag: node_tag_name,
  • props: additional properties, for example, className,
  • style: node styles,
  • events: node events handlers,
  • attrs: for main fields,
  • dataset: list of data-attributes,
  • children: array of child elements, optional
  • text: node text content,
  • html: HTML-content of node

Note: Parameters text, html and children are not mutually compatible.

context Link to context, in which the node must be created, optional.

Returned value

This function returns the link to the created node.

Examples

BX.create('input', {'attrs':{'readonly':'readonly'}, props{...}});

The method is unreplaceable, when creating a new DOM structure, the events must be added to elements as follows:

var completeAction = function(){
   console.log(BX.proxy_context);
};

BX.ready(function(){
   BX.insertAfter(BX.create('span', {
      attrs: {
         className: 'task-view-button'
      },
      dataset: {
         aaa: 123
      }
      events: {
         click: BX.proxy(completeAction, this)
      },
      text: 'Complete'
   }), completeButton);
});


© «Bitrix24», 2001-2024