1.0.1 • Published 6 years ago

itty-js v1.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

itty-js

itty-js aims to be an easy to use, extensibile dom traversal library

Below is the current api, however being a young project certain actions are likely to change in future revisions.


Installing:

yarn add 'itty-js'

Importing:

import { itty as i } from 'itty-js'

Usage:

i('#myIdentifier').addClass('secondClass')

ActionArgumentsExample
constructorselector, context (optional)i('.myClass', document)
ntypei('.myClass').n('div') outputs: <div class='myClass'></div>
addClassclassNamei('.myClass').addClass('classTwo') multiple classes can be passed as and array 'one','two', or a space/period seperated string "one two.three"
removeClassclassNamei('.myClass').removeClass('classTwo')
onevent, actioni('.myClass').on('click', () => console.log('click') or i('.myClass').on('click', myFunction)
offevent, action, useCapture (optional)i('.myClass').off('click', myFunction)
addChildtypei('.myClass').addChild('span') or i('.myClass').addChild( $('.title').n('h1') )
replacehtmli('.myClass').replace('<span></span>') or i('.myClass').replace( $('.title').n('h1') )
htmlhtmli('.myClass').html('<span>Hello</span>') or i('.myClass').html('Hello, World!')
texttexti('.myClass').text('Hello, World!')
cleari('.myClass').clear()
firsti('.myListItems').first()
lasti('.myListItems').last()
stylecssObjecti('.myClass').style({ fontSize: '28px', background: '#eee', margin: '5px' })

Internally most of the classes rely on the loop method which accepts two arrays and itterates over all of the selected itty nodes. for example the style action mentioned above itterates through the nodes and sets node.styleobjectKey = objectValue.

style(cssObj) {
  for (const css of Object.keys(cssObj)) {
    this.loop(['style', css], cssObj[css])
  }
  return this
}
1.0.1

6 years ago

1.0.0

6 years ago