Element based functions.
Members
-
<static> Events :Arrays
-
Stored Element Events.
Type:
- Arrays
Methods
-
<static> $(id)
-
Returns HTMLElement based on id attriube.
Parameters:
Name Type Description idString The id of the element to return.
Returns:
- Type
- HTMLElement
-
<static> $C(cn [, parent])
-
Returns an element based on class name.
Parameters:
Name Type Argument Default Description cnString The class name of the element.
parentHTMLElement <optional>
document The parent element, default is
document.Returns:
- Type
- HTMLElement
-
<static> _$(tag [, parent])
-
Returns an element based on tag. If you provide a parent you can limit the amount of elements that get returned.
Parameters:
Name Type Argument Default Description tagString The tag name of the element.
parentHTMLElement <optional>
document The parent element, default is
document.Returns:
- Type
- HTMLElement
-
<static> addClass(elem, classN)
-
Adds a class name to the element passed.
Parameters:
Name Type Description elemHTMLElement The element to add a class name to.
classNString The class name to add.
-
<static> clean(node)
-
Returns an element without whitespace.
Parameters:
Name Type Description nodeHTMLElement The element to remove whitespace from.
Returns:
- Type
- HTMLElement
-
<static> clicked(evt)
-
Returns element that was clicked on.
Parameters:
Name Type Description evtEvent The event object.
Returns:
- Type
- HTMLElement
-
<static> collides(arg1, arg2)
-
Returns
trueorfalseif an element collides with another one.Parameters:
Name Type Description arg1HTMLElement | Object Element to detect collision or object with coordinates.
arg2HTMLElement | Object Second element to detect collision or object with coordinates.
Returns:
- Type
- Boolean
Example
var elem1 = ML.El.$('test-elem-1'); var elem2 = {width: 100, height: 300, x: 0, y: 200}; // You can also pass in an var collides = ML.El.collides(elem1, elem2); // object of coordinates. // i.e. width, height, x and y. if (collides) { console.log('Elements are colliding.'); } else { console.log('No collision detected.') } -
<static> create(element [, attrs])
-
Returns an element to be created in the DOM with attributes passed.
Parameters:
Name Type Argument Description elementHTMLElement The tag to create, i.e.
div.attrsObject <optional>
Attributes to add to tag.
Returns:
- Type
- HTMLElement
Example
// NOTE: When setting class name make sure to put in quotes, see example: var div = ML.El.create('div', {'id': 'test-elem', 'class': 'cool-div'}); -
<static> data(element, attr)
-
Returns a data attribute.
Parameters:
Name Type Description elementHTMLElement The element to get the data attribute value for.
attrString The data attribute, excluding
data-.Returns:
- Type
- String | Number
-
<static> dimens(elem)
-
Returns the width, height, x and y position of an element.
Parameters:
Name Type Description elemHTMLElement The element's dimensions.
Returns:
- Type
- Object
-
<static> evt(el, type, cb [, capture])
-
Event listener bound to elements.
Parameters:
Name Type Argument Description elHTMLElement The element to bind an event to.
typeString The type of event.
cbfunction Callback function.
Properties
Name Type Description eEvent The Event Object.
captureBoolean <optional>
-
<static> evtTrigger(el, type)
-
Trigger events bound to elements.
Parameters:
Name Type Description elHTMLElement The element to trigger an event on.
typeString The type of event to trigger.
-
<static> findParent(el, tag, classN)
-
Returns parent element specified. Returns false if element is not found.
Parameters:
Name Type Description elHTMLElement The child element to search for ancestor elements.
tagString Name of tag to search for.
classNString Class name of the tag to search for.
Returns:
- Type
- HTMLElement | Boolean
-
<static> getAttr(element, attr)
-
Returns attribute value for passed attribute.
Parameters:
Name Type Description elementHTMLElement The element to get the attribute value for.
attrString The attribute to get a value from.
Returns:
- Type
- String | Number
-
<static> getStyle(element, styleProp)
-
Returns a style for a specific element.
Parameters:
Name Type Description elementHTMLElement The element to get styles for.
stylePropString Style property to get the value of.
Returns:
- Type
- Object
-
<static> hasClass(elem, classN)
-
Returns
trueorfalseif an element has a specific class name.Parameters:
Name Type Description elemHTMLElement Element to check if it has a specific class name.
classNString The class name to check for.
Returns:
- Type
- Boolean
-
<static> isBound(node, type, funcName)
-
Returns
trueorfalseif an event is bound to an element.Parameters:
Name Type Description nodeHTMLElement The HTML element to track.
typeString The type of event, i.e.
click,focusetc...funcNameString The name of the function bound to the element.
Returns:
- Type
- Boolean
-
<static> position(elem)
-
Returns the x and y position of an element.
Parameters:
Name Type Description elemHTMLElement The element's x and y position.
Returns:
- Type
- Object
-
<static> removeClass(elem, classN [, multiple])
-
Removes a class name from an element. credit
Parameters:
Name Type Argument Description elemHTMLElement The element of the class name to be removed.
classNString Class names to be removed.
multipleBoolean <optional>
If there are multiple class names to be removed.
-
<static> removeEvt(el, type, cb [, capture])
-
Remove event listener bound to an element.
Parameters:
Name Type Argument Description elHTMLElement The element to remove the event from.
typeString The type of event.
cbfunction Callback function.
Properties
Name Type Description eEvent The Event Object.
captureBoolean <optional>
-
<static> setStyles(element, props)
-
Styles an element.
Parameters:
Name Type Description elementHTMLElement The element to set styles to.
propsObject Style properties and values.
-
<static> toggleClass(elem, classN [, cond])
-
Toggles the class name of an element.
Parameters:
Name Type Argument Description elemHTMLElement The element to toggle class name.
classNString The class name to toggle.
condBoolean <optional>
Boolean value to determine whether class name should be added or removed.