Elmo

Elmo

Represents Elmo!

Constructor

new Elmo(selector)

Source:
Example
var divs = new Elmo('div')
Parameters:
Name Type Description
selector String | HTMLElement Must be a valid selector or a HTMLElement

Methods

_getAttr(name) → {String|null}

Source:
Get the value of an attribute of the first element in the selected elements.
Example
var divs = new Elmo('div')
divs._getAttr('class')
Parameters:
Name Type Description
name String The name of the attribute to get.
Returns:
If the attribute exists, then the value is returned. If the attribute does not exist, or there are no selected elements, then null is returned.
Type
String | null

_getData(key) → {String|null}

Source:
Get the value of a dataset of the first element in the selected elements.
Example
var divs = new Elmo('div')
divs._getData('hello')
Parameters:
Name Type Description
key String The data key to get
Returns:
Type
String | null

_setAttr(name, value)

Source:
Set an attribute of all the selected elements.
Example
var divs = new Elmo('div')
divs._setAttr('awesome', 'oh! yeah')
Parameters:
Name Type Description
name String The name of the attribute whose value has to be set.
value * The value of the attribute to set.

_setData(key, value)

Source:
Set data on all the selected elements. _setData can either accept a single object parameter or 2 parameters - key and value.
Example
var divs = new Elmo('div')
// Using Object
divs._setData({cats: 1, dogs: 12})
// Using key and value
divs._setData('mangoes', 134)
Parameters:
Name Type Default Description
key String | Object If this parameter is a string, this acts as the key. This is used for storing data on the element. If this parameter is an object, then value parameter is ignored. The keys and values within the object will be used to set the data.
value * null

addClass(className) → {Elmo}

Source:
Add a class to all the selected elements.
Example
var divs = new Elmo('div')
divs.addClass('hello')
Parameters:
Name Type Description
className String The name of the class to add.
Returns:
Type
Elmo

attr(name, value)

Source:
If only name is present, Elmo#_getAttr will be called. If name and value are both present, Elmo#_setAttr will be called.
Parameters:
Name Type Default Description
name String
value * null
Throws:
If neither name or value is present, this exception will be thrown.

css(style) → {Elmo}

Source:
Set style on the selected elements.
Example
var divs = new Elmo('div')
divs.css({background: 'pink', margin: '1px'})
divs.css('color: blue; border: 1px solid black;')
divs.css('') // this will clear all the styles
Parameters:
Name Type Description
style Object | String The style object/string. If you pass a object, the keys should be valid css properties and the values should be valid css property values.
Returns:
Type
Elmo

data(key, value)

Source:
If only key is present, Elmo#_getData will be called. If key and value are both present, Elmo#_setData will be called.
Parameters:
Name Type Default Description
key String | Object
value * null
Throws:
If neither key or value is present, this exception will be thrown.

on(eventType, listener) → {Elmo}

Source:
Add a event listener to the selected elements.
Example
var divs = new Elmo('div')
divs.on('click', function () {
     console.log(this)
})
Parameters:
Name Type Description
eventType String The type of event you are listening to.
listener function The listener function that will be called when the event is triggered.
Returns:
Type
Elmo

removeClass(className) → {Elmo}

Source:
Remove a class to all the selected elements.
Example
var divs = new Elmo('div')
divs.removeClass('hello')
Parameters:
Name Type Description
className String The name of the class to remove.
Returns:
Type
Elmo