Skip to content

Latest commit

 

History

History
542 lines (197 loc) · 7.49 KB

API.md

File metadata and controls

542 lines (197 loc) · 7.49 KB

Manipulate collection of DOM elements

src/index.js

new GaspardCollection([elements=])

Use GaspardCollection class to perform actions on Elements

Parameters
Name Type Description
elements= Array.<Element> Element string DOM Elements, Element, or string to query the DOM Optional
Examples
import GaspardCollection from 'gaspard-collection'
const collection = new GaspardCollection('div.highlight')
collection
  .css('background-color', 'green')
  .find('p:first-child') // returns a new gaspard collection
  .addClass('introduction')
  .fadeIn(400)
  .elements // Array of matched elements
  .forEach(element => {
    console.log('div.highlight first paragraph', element)
  })
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.each(method, params)

Apply a method on each elements and returns the collection to chain methods

Parameters
Name Type Description
method Function Accept a method to run on each elements  
params any A list of argument to call the method with  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.addClass(classNames)

Add classes to each elements

Parameters
Name Type Description
classNames string  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.toggleClass(classNames, state)

Toggle classes to each elements

Parameters
Name Type Description
classNames string  
state boolean  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.removeClass(classNames)

Remove classes to each elements

Parameters
Name Type Description
classNames string  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.attr(attribute, value)

Set attribute to each elements

Parameters
Name Type Description
attribute string  
value any  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.css(ruleName, value)

Set CSS value to each elements

Parameters
Name Type Description
ruleName string  
value string  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.before(htmlString)

Insert content before each elements

Parameters
Name Type Description
htmlString string  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.after(htmlString)

Insert content after each elements

Parameters
Name Type Description
htmlString string  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.prepend(element)

Prepend element to each elements

Parameters
Name Type Description
element Element  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.append(element)

Append element to each elements

Parameters
Name Type Description
element Element  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.remove()

Remove each elements

Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.text(textString)

Set text to each elements

Parameters
Name Type Description
textString string  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.html(htmlString)

Set html to each elements

Parameters
Name Type Description
htmlString string  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.replaceWith(htmlString)

Replace each elements

Parameters
Name Type Description
htmlString string  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.fadeIn(duration)

Fade in each elements

Parameters
Name Type Description
duration number  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.fadeOut(duration)

Fade out each elements

Parameters
Name Type Description
duration number  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.hide()

Hide each elements

Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.show()

Show each elements

Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.on(eventName, eventHandler)

Attach an event handler function for each elements

Parameters
Name Type Description
eventName string  
eventHandler Function  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.off(eventName, eventHandler)

Remove an event handler function for each elements

Parameters
Name Type Description
eventName string  
eventHandler Function  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.trigger(eventName, data)

Execute all handlers to each elements

Parameters
Name Type Description
eventName string  
data Object  
Returns
  • GaspardCollection GaspardCollection containing elements

GaspardCollection.find(selectorOrElement)

Returns a collection of matched elements either found in the DOM based on passed argument

Parameters
Name Type Description
selectorOrElement string Element Accepts a string containing a CSS selector which is then used to match a set of elements, or an Element  
Returns
  • GaspardCollection GaspardCollection containing elements

Documentation generated with doxdox.