Skip to content

iondrimba/nojquery

Repository files navigation

NoJQuery

Used for personal projects/simple apps with little DOM interactions.

Travis build status Build status Coverage Status

Minified version: 6kb

Gziped version: 2kb

Implementation :

UMD ready. It can be loaded via AMD, CommonJs and as global namespace.

AMD

define(['nojquery'], function(NoJQuery){
    var $$ = NoJQuery;
});

CommonJS

var $$ = require('nojquery');

Global namespace

var $$ = window.NoJQuery;

API

find :

var result = $$('selector').find('child-element');
console.log(result.elmts[0]);
addClass :

$$('selector').addClass('some-class');
hasClass :

var bool = $$('selector').hasClass('some-class');
console.log(bool);
removeClass :

$$('selector').removeClass('some-class');
contains :

var result = $$('selector').contains('some-selector');
console.log(result);
empty :

$$('selector').empty();
text :

$$('selector').text('Hello');
html :

$$('selector').html('<a href="/" > Link </a>');
getAttr :

var result = $$('selector').getAttr('attrName');
console.log(result);
setAttr :

$$('selector').setAttr('readonly', 1);
removeAttr :

$$('selector').removeAttr('readonly');
remove :

$$('selector').remove();
next :

var result = $$('selector').next();
console.log(result.elmts[0]);
prev :

var result = $$('selector').prev();
console.log(result.elmts[0]);
append :

$$('selector').append('<div>Hello</div>');
$$('selector').append($$('selector-elmt'));
prepend :

$$('selector').prepend('<div>Hello</div>');
$$('selector').prepend($$('selector-elmt'));
on :

function onButtonClick(evt) {
    console.log('click', evt.currentTarget);
};
$$('selector').on('click', onButtonClick);
off :

$$('selector').off('click', onButtonClick);