DOM

Namespace

DOM

Description:
  • By importing BIMSDK, functions are added to DOM Element.

    Use function bim.app.element to get DOM Element Object.

    Below methods can be called with DOM Element.


Source:
Properties:
Name Type Description
is function

Function to check whether the element corresponds to the selector or not. See DOM.is for more details.

find function

Function to find Objects from the element with the selector. See DOM.find for more details.

filter function

Function to filter the element through a function given as a parameter. See DOM.filter for more details.

append function

Function to append array in arguments to the element. See DOM.append for more details.

last function

Function that returns the last element of the array. See DOM.last for more details.

eq function

Function that returns the element corresponding to the location of the array. See DOM.eq for more details.

index function

Function that returns the index number of the element from the array. See DOM.index for more details.

forEach function

Function to run the given callback function for each element. See DOM.forEach for more details.

parent function

Function to get the ancestor of each element matched to the selector. See DOM.parent for more details.

parents function

Function to get all the ancestors of each element matched to the selector. See DOM.parents for more details.

closest function

Function to get the closest DOM object from parent node and itself. See DOM.closest for more details.

addClass function

Function to add classes to current element. See DOM.addClass for more details.

removeClass function

Function to remove classes from current element. See DOM.removeClass for more details.

hasClass function

Function to check whether current element has specific class. See DOM.hasClass for more details.

attr function

Function to get or set the value of attribute of the element. See DOM.attr for more details.

removeAttr function

Function to remove the given attribute from the element. See DOM.removeAttr for more details.

prop function

Function to get or set the value of the given property of the element. See DOM.prop for more details.

val function

Function to get or set the value of the element. See DOM.val for more details.

remove function

Function to remove the current element from parentNode. See DOM.remove for more details.

empty function

Function to remove all the childNodes from the current element. See DOM.empty for more details.

on function

Function to bind eventListener and handleEvent to the element. See DOM.on for more details.

off function

Function to remove binded eventListener from the elemnet. See DOM.off for more details.

text function

Function to get or set the text value of the element. See DOM.text for more details.

Methods

(static) is(selector) → {boolean}

Description:
  • Function to check whether the element corresponds to the selector or not.

Source:
Examples
if (bim.app.element(${1:selector}).is(${2:selector})) {
 // Do something ...
}
if (bim.app.element("#bimId").is(".bimClass")) {
 // Do something ...
}
Parameters:
Name Type Description
selector string | DOM

The selector to compare elements. Should be in string or DOM Object types.

Returns:

Whether the element matches the selector.

true | false

Type
boolean

(static) find(selector) → {Array}

Description:
  • Function to find all Objects with the selector from the element

Source:
Examples
bim.app.element(${1:selector}).find(${2:selector});
let foundElements = bim.app.element("bim").find("div");
Parameters:
Name Type Description
selector string | Object

The selector which would be used in the query. Should be in string or DOM Object types.

Returns:

Found Objects in Array type.

Type
Array

(static) filter(callback) → {Array.<DOM>}

Description:
  • Function to filter the element through the given function which is handed over as a parameter.

Source:
Examples
bim.app.element(${1:selector}).filter(${2:function});
let filteredElements = bim.app.element(".bimElements").filter(function (obj) {
 // Return {boolean} ..
 return obj.is(".bimClass");
});
Parameters:
Name Type Description
callback function

Filter function ({DOM}, {number}, {DOM})

returns {boolean}

Returns:

Filtered Objects in Array type.

Type
Array.<DOM>

(static) append(args) → {DOM}

Description:
  • Function to append array in arguments to the element.

Source:
Examples
bim.app.element(${1:selector}).append(${2:array});
bim.app.element("bim").append("<div>Hello Bim</div>");
const p = document.createElement("p");
bim.app.element("body").append(p);
Parameters:
Name Type Description
args Array

list of objects expected to be appended to the element

Returns:

self

Type
DOM

(static) last() → {boolean|DOM}

Description:
  • Function that returns the last element of the array.

Source:
Examples
bim.app.element(${1:selector}).last();
bim.app.element("div").last();
Returns:

false if the element is undefined or its length equals to 0 | DOM Object at the last of the given Array.

Type
boolean | DOM

(static) eq(index) → {DOM}

Description:
  • Function that returns the element corresponding to the location of the array.

Source:
Examples
bim.app.element(${1:selector}).eq(${2:index});
let listItem = bim.app.element("li").eq(3);
Parameters:
Name Type Description
index number

A number for where Object in Array is located. Should be a positive, or negative Integer.

Returns:

DOM Object located in the array at the index.

Type
DOM

(static) index() → {number}

Description:
  • Function that returns the index number of the element from the array

Source:
Examples
bim.app.element(${1:selector}).index();
bim.app.element("li.bimClass").index();
Returns:

The index of the element from the array.

Type
number

(static) forEach(callback) → {DOM}

Description:
  • Function to run the given callback function for each element. If callback function returns false, terminates the loop early.

Source:
Examples
bim.app.element(${1:selector}).forEach(${2:callback});
bim.app.element("li").forEach(function (item, item2, index) {
 // Do Something ...
 console.log("li : ", item);
});
Parameters:
Name Type Description
callback function

currentvalue, currentvalue, index as params

Returns:

self

Type
DOM

(static) parent(selectoropt) → {DOM}

Description:
  • Function to get the ancestor of each element in the current set of elements matched to the selector.

Source:
Examples
bim.app.element(${1:selector}).parent();
bim.app.element(${1:selector}).parent(${2:selector});
let bimElement = bim.app.element("li").parent("ul");
Parameters:
Name Type Attributes Description
selector string | DOM <optional>

Optional. A string containing a selector expression to match elements against. | DOM Object to compare with.

Returns:

element

Type
DOM

(static) parents(selectoropt) → {DOM}

Description:
  • Function to get all the ancestors of each element in the current set of matched elements matched to the selector. Similar to DOM.parent, except this travels multiple level up the DOM tree.

Source:
Examples
bim.app.element(${1:selector}).parents();
bim.app.element(${1:selector}).parents(${2:selector});
let bimElements = bim.app.element("li").parents("ul");
Parameters:
Name Type Attributes Description
selector string | DOM <optional>

Optional. A string containing a selector expression to match elements against. | DOM Object to compare with.

Returns:

Matched parent DOM Element.

Type
DOM

(static) closest(selector) → {DOM}

Description:
  • Function to get the closest DOM object from parent node and itself. Traverses the element and its parents until it finds a node. If the element is undefined, returns new DOM.

Source:
Examples
bim.app.element(${1:selector}).closest(${2:selector});
let closeElement = bim.app.element("li.bimList").closest("ul");
Parameters:
Name Type Description
selector string | DOM

Required. Valid selector to match the element. | DOM Object to compare with.

Returns:

New DOM Object if selector is undefined, else closest parent DOM Object.

Type
DOM

(static) addClass(className) → {DOM}

Description:
  • Function to add classes to current element. Multiple classes can be added at the same time seperated by "space".

Source:
Examples
bim.app.element(${1:selector}).addClass(${2:className});
bim.app.element("div").addClass("className1 className2 className3");
Parameters:
Name Type Description
className string

Class name

Returns:

Self

Type
DOM

(static) removeClass(className) → {DOM}

Description:
  • Function to remove classes from current element. Multiple classes can be removed at the same time seperated by "space".

Source:
Examples
bim.app.element(${1:selector}).removeClass(${2:className});
bim.app.element("div").removeClass("className1 className2 className3");
Parameters:
Name Type Description
className string

Class name

Returns:

Self

Type
DOM

(static) hasClass(className) → {boolean}

Description:
  • Function to check whether current element has specific class given as parameter.

Source:
Examples
bim.app.element(${1:selector}).hasClass(${2:className});
if (bim.app.element("div").hasClass("className1")) {
 // Do something ...
}
Parameters:
Name Type Description
className string

Class name

Returns:

Whether the element has the class or not.

true | false

Type
boolean

(static) attr(attrs, valueopt) → {string|DOM}

Description:
  • Function to get or set the value of attribute of the element.

Source:
Examples
// Gets current element's attr
bim.app.element(${1:selector}).attr(${2:attrName});
// Sets value to current element's attr
bim.app.element(${1:selector}).attr(${2:attrName}, ${3:value});
// Sets values of the given attributes to the element
bim.app.element(${1:selector}).attr({
 ${2:attrName} : ${3:value},
 ${4:attrName} : ${5:value}
// ...
});
let inputTitle = bim.app.element("input").attr("title");
Parameters:
Name Type Attributes Description
attrs string
value string <optional>
Returns:

Value of attribute when 1 argument, else Self

Type
string | DOM

(static) removeAttr(attr) → {DOM}

Description:
  • Function to remove the given attribute from the element.

Source:
Examples
bim.app.element(${1:selector}).removeAttr(${2:attr});
bim.app.element("input").removeAttr("title");
Parameters:
Name Type Description
attr string

Attribute expected to be removed

Returns:

Self

Type
DOM

(static) prop(props, valueopt) → {string|DOM}

Description:
  • Function to get or set the value of the given property of the element.

Source:
Examples
// Get the value of the given property from the element
bim.app.element(${1:selector}).prop(${2:propName});
// Set the value of the given property to the element
bim.app.element(${1:selector}).prop(${2:propName}, ${3:value});
// Set the values of the given properties to the element
bim.app.element(${1:selector}).prop({
 ${2:propName} : ${3:value},
 ${4:propName} : ${5:value}
// ...
});
let checked = bim.app.element(".checkBox").prop("checked");
Parameters:
Name Type Attributes Description
props string | Object

Property name

value string <optional>

String value for property

Returns:

value of the property of the element | self

Type
string | DOM

(static) val(valueopt) → {string|Array.<string>|DOM}

Description:
  • Function to get or set the value of the element.

Source:
Examples
// Get the value of the element
bim.app.element(${1:selector}).val();
// Set the value of the element
bim.app.element(${1:selector}).val(${2:value});
bim.app.element("input").val("Hello Bim~");
Parameters:
Name Type Attributes Description
value string <optional>

Value to assign

Returns:

Value of the element | Self

Type
string | Array.<string> | DOM

(static) remove() → {DOM}

Description:
  • Function to remove the current element from parentNode.

Source:
Examples
bim.app.element(${1:selector}).remove();
bim.app.element("li").remove();
Returns:

Self | parentNode

Type
DOM

(static) empty() → {DOM}

Description:
  • Function to remove all the childNodes from the current element.

Source:
Examples
bim.app.element(${1:selector}).empty();
bim.app.element("ul").empty();
Returns:

Self

Type
DOM

(static) on(eventType, targetSelectoropt, listener, captureopt) → {DOM}

Description:
  • Function to bind eventListener and handleEvent to the element.

Source:
Examples
// with 2 arguments
bim.app.element(${1:selector}).on(${2:eventType}, ${3:listener});
// with 3 arguments
bim.app.element(${1:selector}).on(${2:eventType}, ${3:targetSelector}, ${4:listener});
// with 4 arguments
bim.app.element(${1:selector}).on(${2:eventType}, ${3:targetSelector}, ${4:listener}, ${5:capture});
Parameters:
Name Type Attributes Default Description
eventType string
targetSelector string <optional>
listener function
capture boolean <optional>
false

true | false

Returns:

Self

Type
DOM

(static) off(eventType, targetSelector, listener, captureopt) → {DOM}

Description:
  • Function to remove binded eventListener from the elemnet.

Source:
To Do:
  • Check the stability
Examples
// with 2 arguments
bim.app.element(${1:selector}).off(${2:eventType}, ${3:listener});
// with 3 arguments
bim.app.element(${1:selector}).off(${2:eventType}, ${3:targetSelector}, ${4:listener});
// with 4 arguments
bim.app.element(${1:selector}).off(${2:eventType}, ${3:targetSelector}, ${4:listener}, ${5:capture});
Parameters:
Name Type Attributes Default Description
eventType string
targetSelector string
listener function
capture boolean <optional>
false

true | false

Returns:

self

Type
DOM

(static) text(text$1opt) → {string|DOM}

Description:
  • Function to get or set the text value of the element.

Source:
Examples
// Get text value of the element
bim.app.element(${1:selector}).text();
// Set text value to the element
bim.app.element(${1:selector}).text(${2:text});
bim.app.elemnt("h1").text("Hello Bim~");
Parameters:
Name Type Attributes Description
text$1 string <optional>

Text value to assign

Returns:

Text value | self

Type
string | DOM