You like jQuery syntax and ES2015 features?
Dom-box is a neat wrapper around DOM APIs with jQuery like syntax. It is designed to fit only your needs. Import just what your app deserves.
$ npm install --save dombox
import $ from 'dom-box';
import {addClass} from 'dom-box/modules/add_class';
$('.msg', addClass('open'));
import $ from 'dom-box';
import wizard from 'dom-box/mod_wizard';
const findTheMightyElements = wizard(function findTheMightyElements() {
const newElements = this.filter(element => {
return element.tagName === 'MIGHTY';
});
return newElements;
});
/*
<div></div>
<mighty></mighty>
<section></section>
*/
$('*', findTheMightyElements()); // [mighty]
- on
- off
- index
- prev
- next
- prevAll
- nextAll
- replaceWith
- wrap
- html
- text
- val
- prop
- attr
- bind (observer)
- remove
- append
- data
Finds elements in the given scope, filtered by the given selector
Parameters
paramSelector
(selector | element) The elements to findparamScope
[(selector | element)] The scope to search for the elements (optional, defaultdocument
)
Returns array A set of elements
Adds one or more classes to each of the selected elements.
Parameters
cssClass
String One or more space separted classes.
Examples
$('div', addClass('foo'));
$('div', addClass('foo bar'));
Returns Array The selected elements.
Removes one or more classes from each of the selected elements.
Parameters
cssClass
String One or more space separted classes.
Examples
$('div', removeClass('foo'));
$('div', removeClass('foo bar'));
Returns Array The selected elements.
Checks if at least one element in the current set contains the given class or classes.
Parameters
cssClass
String One or more space separted classes.
Examples
$('div', addClass('foo'));
$('div', addClass('foo bar'));
Returns Boolean Returns true if there is a match.
Reduces the current set to the first element in the set.
Examples
//<ul>
// <li class="first"></li>
// <li></li>
// <li></li>
//</ul>
$('li', 'ul', first()); // ['li.first']
Returns Array The first element.
Reduces the current set to the last element in the set.
Examples
//<ul>
// <li></li>
// <li></li>
// <li class="last"></li>
//</ul>
$('li', 'ul', last()); // ['li.last']
Returns Array The last element.
Finds the descendants in the current set, filtered by the given selector.
Parameters
selector
String A selector expression.
Examples
//<article>
// <section></section>
// <section></section>
//</article>
$('article', find('section')) // ['section', 'section']
Returns Array A set of fetched elements.
Get the value of the first element or set the value of each element.
Parameters
Examples
// <input type="text" value="foo" />
$('input', val()); // foo
$('input', val('bar')); // <input type="text" value="bar" />
Returns (Array | String) The current set of matched elements if the function is used as setter, or the value of the first element if the function is used as getter.
Display the selected elements.
Examples
$('div', show());
Returns Array The selected elements.
Hide the selected elements.
Examples
$('div', hide());
Returns Array The selected elements.
MIT © Chris Ebert