Namespace: _

_(selector, createopt, contentsopt, strictopt)

SpacerJS, finds/creates an element
Parameters:
Name Type Attributes Description
selector string | HTMLElement A valid selector
create boolean <optional>
Boolean to create an element or not
contents string <optional>
Contents to find element by
strict boolean <optional>
If true, the contents must match the text exactly
License:
  • MIT
Source:

Members

(inner) element

The selected HTMLElement
Source:

(inner) fn

Object of any custom methods you want to add
Source:

(inner) meta

Meta data object
Source:

(inner) nodelist

The selected nodelist
Source:

(inner) state

Object that keeps track of element's meta state
Properties:
Name Type Description
hidden boolean Tracks if element is hidden by hide() or show() meta functions
hovered boolean Tracks if element is hovered by hover() or unhover() meta functions
active boolean Tracks if element is active by active() or unactive() meta functions
Source:

Methods

(inner) __(selector)

Selects and returns a NodeList
Parameters:
Name Type Description
selector string QuerySelectorAll string
Source:

(inner) active()

Adds the activeClass that was set with setMeta(metaObj)
Source:

(inner) addClass(className)

Adds a class to the element
Parameters:
Name Type Description
className string Class Name
Source:

(inner) animate(cssProperty, value, time)

Animates the element
Parameters:
Name Type Description
cssProperty string cssProperty to edit
value string New value of cssProperty
time string Css Transition length, ex: "1s"
Source:

(inner) append(elem)

Appends the a Node or string to a parent element
Parameters:
Name Type Description
elem HTMLElement | Node | String Selector string or HTMLElement
Source:

(inner) appendChild(child)

Appends a child element
Parameters:
Name Type Description
child HTMLElement An HTMLElement
Source:

(inner) appendList(elementlist)

Appends a list of HTML Elements
Parameters:
Name Type Description
elementlist Array.<HTMLElement> Array of Elements or nodes
Source:

(inner) appendTo(parent)

Appends the child element to a parent element
Parameters:
Name Type Description
parent string | HTMLElement Selector string
Source:

(inner) at(index)

Selects an element, not 0 based
Parameters:
Name Type Description
index number Index
Source:
Returns:
Element | undefined
Example
let myElement = _('div').at(5) // gets the fifth child and not the 4th like an array

(inner) attr(attribute, value)

Sets/Creates a attribute to a value
Parameters:
Name Type Description
attribute string Attribute to set/create
value string Value that the Attribute will be set to
Source:

(inner) children()

Returns NodeList
Source:
Returns:
NodeList

(inner) click()

Clicks the element
Source:

(inner) clone(keepChildrenopt)

Clones the element
Parameters:
Name Type Attributes Description
keepChildren boolean <optional>
Keep child elements
Source:
Returns:
Cloned Node

(inner) compareNode(node)

Compares two nodes to see if they are similar
Parameters:
Name Type Description
node HTMLElement | Node HTMLElement or Node
Source:
Returns:
Boolean

(inner) contains(node)

Checks if the element contains a Node
Parameters:
Name Type Description
node Node HTML Node to check for
Source:
Returns:
Boolean

(inner) css(pseudoElementopt)

Retuns computedStyle of element
Parameters:
Name Type Attributes Description
pseudoElement string <optional>
A pseudoElement
Source:
Returns:
CSSStyleDeclaration | null

(inner) dbclick()

Clicks the element twice
Source:

(inner) debug(…args)

Console logs any arguments
Parameters:
Name Type Attributes Description
args any <repeatable>
Any arguments
Source:

(inner) deleteMeta()

Removes metadata
Source:

(inner) each(cb)

Iterate through a nodelist
Parameters:
Name Type Description
cb function Callback with first parameter being value and last being index
Source:

(inner) empty()

Removes all empty child nodes
Source:

(inner) fadeIn(intensityopt)

Fades in the selected element
Parameters:
Name Type Attributes Default Description
intensity number <optional>
0.05 Intensity of the fade
Source:

(inner) fadeOut(intensityopt)

Fades out the selected element
Parameters:
Name Type Attributes Default Description
intensity number <optional>
0.05 Intensity of the fade
Source:

(inner) first(nodeopt)

Returns the first child element as an HTMLelement
Parameters:
Name Type Attributes Default Description
node boolean <optional>
false Determines the returned value as a HTMLElement or Node
Source:
Returns:
HTMLElement

(inner) focus()

Focuses the element
Source:

(inner) hasAttr(attribute)

Checks if the element has an certain attribute
Parameters:
Name Type Description
attribute string Attribute
Source:
Returns:
Boolean

(inner) hasChildren(normalize)

Checks if an element has any child nodes
Parameters:
Name Type Description
normalize boolean Boolean to normalize before checking for child nodes
Source:
Returns:
Boolean

(inner) hide()

Adds the hidden class that was set with setMeta()
Source:

(inner) hover()

Adds the hoverClass that was set with setMeta(metaObj)
Source:

(inner) html(str)

Appends the a string to the selected element innerHTML
Parameters:
Name Type Description
str string String to be inserted in the innerHTML
Source:

(inner) keydown(cb)

Listens for the keydown event
Parameters:
Name Type Description
cb function Callback
Source:

(inner) keyup(cb)

Listens for the keyup event
Parameters:
Name Type Description
cb function Callback
Source:

(inner) kill()

Removes the element
Source:

(inner) last(nodeopt)

Returns the last child element as an HTMLelement
Parameters:
Name Type Attributes Default Description
node boolean <optional>
false Determines the returned value as a HTMLElement or Node
Source:
Returns:
HTMLElement

(inner) normalize()

Converts text nodes into text content
Source:

(inner) offset()

Returns the top and left coordianate
Source:
Returns:
object.top & object.left

(inner) on(event, cb)

Sets on event listener and runs cb on event
Parameters:
Name Type Description
event string One event or multiple events seperated by one space
cb function | Array.<function()> A callback function or an array of callback functions that will be called by their index of events
Source:

(inner) parent()

Returns the parent element
Source:
Returns:
HTMLElement

(inner) prepend(elem)

Appends the a Node or string to a parent element
Parameters:
Name Type Description
elem HTMLElement | Node | String Selector string or HTMLElement
Source:

(inner) prependList(elementlist)

Appends a list of HTML Elements
Parameters:
Name Type Description
elementlist Array.<HTMLElement> Array of Elements or nodes
Source:

(inner) prependTo(parent)

Appends the child element to a parent element
Parameters:
Name Type Description
parent string | HTMLElement Selector string
Source:

(inner) randomChild()

Returns a random child
Source:
Returns:
HTMLElement | Node | null

(inner) removeChild(node)

Removes a child node
Parameters:
Name Type Description
node HTMLElement | Node HTMLElement or Node
Source:

(inner) removeChildren()

Removes all child nodes
Source:

(inner) removeClass(className)

Removes a class from the element
Parameters:
Name Type Description
className string Class Name
Source:

(inner) removeMetaProp(metaKey)

Removes a property of Metadata
Parameters:
Name Type Description
metaKey string hiddenClass, hoverClass, or activeClass
Source:

(inner) replaceChild(newChild, oldChild)

Replaces a child element
Parameters:
Name Type Description
newChild HTMLElement | Node New Element
oldChild HTMLElement | Node Old Element
Source:

(inner) rotate(cssValue)

Sets the rotation of an element
Parameters:
Name Type Description
cssValue string Any valid CSS Rotate Tranform
Source:
Example
myElement.rotate('0.5turn')

(inner) setMeta(obj)

Sets the "metadata" of a element for showing passed classes, and other methods
Parameters:
Name Type Description
obj object Meta Data Object
Properties
Name Type Attributes Description
hiddenClass string <optional>
Class to be used when using hide() or show()
hoverClass string <optional>
Class to be used when using hover() or unhover()
activeClass string <optional>
Class to be used when using active() or unactive()
Source:

(inner) setTitle()

Sets the element's title
Source:

(inner) show()

Removes the hidden class that was set with setMeta()
Source:

(inner) size()

Returns the Bounding Client Rect
Source:
Returns:
DomRect

(inner) sleep(ms)

Sleep promise
Parameters:
Name Type Description
ms number Millisecond delay
Source:
Returns:
Promise

(inner) sToView(alignToopt)

Scrolls the element into view
Parameters:
Name Type Attributes Description
alignTo boolean <optional>
True or false, true lines up element to the top of the screen
Source:

(inner) text(str)

Appends the a string to the selected element innerText
Parameters:
Name Type Description
str string String to be inserted in the innerText
Source:

(inner) toStr()

Returns an HTML Element into a string
Source:
Returns:
String or null

(inner) transform(cssValue)

Sets the transform of an element
Parameters:
Name Type Description
cssValue string Any valid CSS Tranform
Source:
Example
myElement.transform('translate(120px, 50%)')

(inner) trigger(event)

Triggers an event
Parameters:
Name Type Description
event string Event
Source:

(inner) unactive()

Adds the activeClass that was set with setMeta(metaObj)
Source:

(inner) unfocus()

Removes focus from the element
Source:

(inner) unhover()

Adds the hoverClass that was set with setMeta(metaObj)
Source:

(inner) val(newValueopt)

Returns the value of an input element and sets the input value
Parameters:
Name Type Attributes Description
newValue string | any <optional>
New value to set the input value to, optional
Source:
Returns:
HTMLInputElement Value