Documentation

Search functions

Array|DOMNode 
BX.findChild(
 DOMNode obj,
 Object params, 
 bool recursive
 get_all
);
array|DOMNode 
BX.findChildren(
 DOMNode obj,
 Object params, 
 bool recursive
);
DOMNode 
BX.findParent(
 DOMNode obj,
 Object params, 
);
DOMNode 
BX.findNextSibling(
 DOMNode obj,
 Object params, 
);
DOMNode 
BX.findPreviousSibling(
 DOMNode obj,
 Object params, 
);

Search functions for DOM structure nodes via sets of parameters.

Note: BX.findChildren(obj, params, recursive) - синоним BX.findChild(obj, params, recursive, true).

Function parameters

Parameter Description
DOMNode obj Search object
params Format of the object, describing the search parameters:
  • tagName|tag: tag name of the required node,
  • className|class: CSS-class that must support the required node ,
  • attribute: {attribute: value, attribute: value} | attribute | [attribute, attribute....], - either an object with the list and specific values of attributes, or an attribute or array of attributes, which shall be available in the required node
  • property: {prop: value, prop: value} | prop | [prop, prop] - either an object with properties and specific values of properties, or a property of an array of properties, which shall be available in the required node

Note: Filtering function can be specified instead of set of parameters. This function will be called for each checked DOM structure node. The function must return true or false.

recursive show, that the search must be performed not only directly in the nodes' child elements, but in the complete subtree. By default – false (search only in child elements).
get_all return all the found elements as an array.

Examples of use

var body = BX.findParent(BX("bx-panel"), {"tag" : "body"});
console.log(body);
obSelect = BX.findChild(BX("menu"), {
		"tag" : "li",
		"class" : "select"
	}, 
	true
);
obNotEmptyListItem = BX.findChild(
    BX("menu"), 
    function(el) {
        return el.tagName.toUpperCase() == 'LI' && !!el.firstChild
    }, 
    true
);

The example, similar to $.each: to find all step children of id BX(this._id + '_placeholder') with the crm-qpe-field class, and apply actions to them.

var fields = BX.findChild(BX(this._id + '_placeholder'), {class: 'crm-qpe-field'}, true, true);
fields.forEach(function(element){
   console.log(element.getAttribute('name'));
});

For jquery it is approx. as follows:

$.each($( '#' + this ._id + '_placeholder .crm-qpe-field'), function(i, e){
   console.log($(e).attr('name'));
});


© «Bitrix24», 2001-2024
Up