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 |
Members
(inner) element
The selected HTMLElement
(inner) fn
Object of any custom methods you want to add
(inner) meta
Meta data object
(inner) nodelist
The selected nodelist
(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 |
Methods
(inner) __(selector)
Selects and returns a NodeList
Parameters:
| Name | Type | Description |
|---|---|---|
selector |
string | QuerySelectorAll string |
(inner) active()
Adds the activeClass that was set with setMeta(metaObj)
(inner) addClass(className)
Adds a class to the element
Parameters:
| Name | Type | Description |
|---|---|---|
className |
string | Class Name |
(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" |
(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 |
(inner) appendChild(child)
Appends a child element
Parameters:
| Name | Type | Description |
|---|---|---|
child |
HTMLElement | An HTMLElement |
(inner) appendList(elementlist)
Appends a list of HTML Elements
Parameters:
| Name | Type | Description |
|---|---|---|
elementlist |
Array.<HTMLElement> | Array of Elements or nodes |
(inner) appendTo(parent)
Appends the child element to a parent element
Parameters:
| Name | Type | Description |
|---|---|---|
parent |
string | HTMLElement | Selector string |
(inner) at(index)
Selects an element, not 0 based
Parameters:
| Name | Type | Description |
|---|---|---|
index |
number | Index |
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 |
(inner) children()
Returns NodeList
Returns:
NodeList
(inner) click()
Clicks the element
(inner) clone(keepChildrenopt)
Clones the element
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
keepChildren |
boolean |
<optional> |
Keep child elements |
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 |
Returns:
Boolean
(inner) contains(node)
Checks if the element contains a Node
Parameters:
| Name | Type | Description |
|---|---|---|
node |
Node | HTML Node to check for |
Returns:
Boolean
(inner) css(pseudoElementopt)
Retuns computedStyle of element
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
pseudoElement |
string |
<optional> |
A pseudoElement |
Returns:
CSSStyleDeclaration | null
(inner) dbclick()
Clicks the element twice
(inner) debug(…args)
Console logs any arguments
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
Any arguments |
(inner) deleteMeta()
Removes metadata
(inner) each(cb)
Iterate through a nodelist
Parameters:
| Name | Type | Description |
|---|---|---|
cb |
function | Callback with first parameter being value and last being index |
(inner) empty()
Removes all empty child nodes
(inner) fadeIn(intensityopt)
Fades in the selected element
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
intensity |
number |
<optional> |
0.05 | Intensity of the fade |
(inner) fadeOut(intensityopt)
Fades out the selected element
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
intensity |
number |
<optional> |
0.05 | Intensity of the fade |
(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 |
Returns:
HTMLElement
(inner) focus()
Focuses the element
(inner) hasAttr(attribute)
Checks if the element has an certain attribute
Parameters:
| Name | Type | Description |
|---|---|---|
attribute |
string | Attribute |
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 |
Returns:
Boolean
(inner) hide()
Adds the hidden class that was set with setMeta()
(inner) hover()
Adds the hoverClass that was set with setMeta(metaObj)
(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 |
(inner) keydown(cb)
Listens for the keydown event
Parameters:
| Name | Type | Description |
|---|---|---|
cb |
function | Callback |
(inner) keyup(cb)
Listens for the keyup event
Parameters:
| Name | Type | Description |
|---|---|---|
cb |
function | Callback |
(inner) kill()
Removes the element
(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 |
Returns:
HTMLElement
(inner) normalize()
Converts text nodes into text content
(inner) offset()
Returns the top and left coordianate
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 |
(inner) parent()
Returns the parent element
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 |
(inner) prependList(elementlist)
Appends a list of HTML Elements
Parameters:
| Name | Type | Description |
|---|---|---|
elementlist |
Array.<HTMLElement> | Array of Elements or nodes |
(inner) prependTo(parent)
Appends the child element to a parent element
Parameters:
| Name | Type | Description |
|---|---|---|
parent |
string | HTMLElement | Selector string |
(inner) randomChild()
Returns a random child
Returns:
HTMLElement | Node | null
(inner) removeChild(node)
Removes a child node
Parameters:
| Name | Type | Description |
|---|---|---|
node |
HTMLElement | Node | HTMLElement or Node |
(inner) removeChildren()
Removes all child nodes
(inner) removeClass(className)
Removes a class from the element
Parameters:
| Name | Type | Description |
|---|---|---|
className |
string | Class Name |
(inner) removeMetaProp(metaKey)
Removes a property of Metadata
Parameters:
| Name | Type | Description |
|---|---|---|
metaKey |
string | hiddenClass, hoverClass, or activeClass |
(inner) replaceChild(newChild, oldChild)
Replaces a child element
Parameters:
| Name | Type | Description |
|---|---|---|
newChild |
HTMLElement | Node | New Element |
oldChild |
HTMLElement | Node | Old Element |
(inner) rotate(cssValue)
Sets the rotation of an element
Parameters:
| Name | Type | Description |
|---|---|---|
cssValue |
string | Any valid CSS Rotate Tranform |
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
|
(inner) setTitle()
Sets the element's title
(inner) show()
Removes the hidden class that was set with setMeta()
(inner) size()
Returns the Bounding Client Rect
Returns:
DomRect
(inner) sleep(ms)
Sleep promise
Parameters:
| Name | Type | Description |
|---|---|---|
ms |
number | Millisecond delay |
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 |
(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 |
(inner) toStr()
Returns an HTML Element into a string
Returns:
String or null
(inner) transform(cssValue)
Sets the transform of an element
Parameters:
| Name | Type | Description |
|---|---|---|
cssValue |
string | Any valid CSS Tranform |
Example
myElement.transform('translate(120px, 50%)')
(inner) trigger(event)
Triggers an event
Parameters:
| Name | Type | Description |
|---|---|---|
event |
string | Event |
(inner) unactive()
Adds the activeClass that was set with setMeta(metaObj)
(inner) unfocus()
Removes focus from the element
(inner) unhover()
Adds the hoverClass that was set with setMeta(metaObj)
(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 |
Returns:
HTMLInputElement Value