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 id
String 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 cn
String The class name of the element.
parent
HTMLElement <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 tag
String The tag name of the element.
parent
HTMLElement <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 elem
HTMLElement The element to add a class name to.
classN
String The class name to add.
-
<static> clean(node)
-
Returns an element without whitespace.
Parameters:
Name Type Description node
HTMLElement The element to remove whitespace from.
Returns:
- Type
- HTMLElement
-
<static> clicked(evt)
-
Returns element that was clicked on.
Parameters:
Name Type Description evt
Event The event object.
Returns:
- Type
- HTMLElement
-
<static> collides(arg1, arg2)
-
Returns
true
orfalse
if an element collides with another one.Parameters:
Name Type Description arg1
HTMLElement | Object Element to detect collision or object with coordinates.
arg2
HTMLElement | 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 element
HTMLElement The tag to create, i.e.
div
.attrs
Object <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 element
HTMLElement The element to get the data attribute value for.
attr
String 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 elem
HTMLElement The element's dimensions.
Returns:
- Type
- Object
-
<static> evt(el, type, cb [, capture])
-
Event listener bound to elements.
Parameters:
Name Type Argument Description el
HTMLElement The element to bind an event to.
type
String The type of event.
cb
function Callback function.
Properties
Name Type Description e
Event The Event Object.
capture
Boolean <optional>
-
<static> evtTrigger(el, type)
-
Trigger events bound to elements.
Parameters:
Name Type Description el
HTMLElement The element to trigger an event on.
type
String 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 el
HTMLElement The child element to search for ancestor elements.
tag
String Name of tag to search for.
classN
String 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 element
HTMLElement The element to get the attribute value for.
attr
String 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 element
HTMLElement The element to get styles for.
styleProp
String Style property to get the value of.
Returns:
- Type
- Object
-
<static> hasClass(elem, classN)
-
Returns
true
orfalse
if an element has a specific class name.Parameters:
Name Type Description elem
HTMLElement Element to check if it has a specific class name.
classN
String The class name to check for.
Returns:
- Type
- Boolean
-
<static> isBound(node, type, funcName)
-
Returns
true
orfalse
if an event is bound to an element.Parameters:
Name Type Description node
HTMLElement The HTML element to track.
type
String The type of event, i.e.
click
,focus
etc...funcName
String 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 elem
HTMLElement 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 elem
HTMLElement The element of the class name to be removed.
classN
String Class names to be removed.
multiple
Boolean <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 el
HTMLElement The element to remove the event from.
type
String The type of event.
cb
function Callback function.
Properties
Name Type Description e
Event The Event Object.
capture
Boolean <optional>
-
<static> setStyles(element, props)
-
Styles an element.
Parameters:
Name Type Description element
HTMLElement The element to set styles to.
props
Object Style properties and values.
-
<static> toggleClass(elem, classN [, cond])
-
Toggles the class name of an element.
Parameters:
Name Type Argument Description elem
HTMLElement The element to toggle class name.
classN
String The class name to toggle.
cond
Boolean <optional>
Boolean value to determine whether class name should be added or removed.