Vanilla JavaScript is good but the function names are too long. Now, you can use vanilla DOM API with jQuery-like functions.
Only ~1kB (without gzip) after uglifying. You can even tailor for yourself to make it much smaller, by deleting/adding modules. A good choice to manipulate DOM for side projects.
njq works with vailla DOMElement. No jQuery collection unless you use $.eachCall to iterate and call functions (see below).
$(selector[, parent])returns DOMElement$$(selector[, parent])returns DOMList
$.each(array, callback)same asforEach. the callback function accepts two arguments:(index, element)and may returnfalseto interrupt iterating.$.eachCall(func, array, ...args)apply every element ofarrayas the first argument, then callfuncwith rest argumentsargsthisis the current element while iterating.- Example:
$.eachCall( $.addClass , $$('button') , 'blazing-button' )$.eachCall( $.attr , $$('button') , 'style', 'color: red' )$.eachCall( $.bind , jQuery('.p') , 'click', onClickFunction )$.eachCall( window.alert, [ "Hello", "World" ] )
$.bind(element, eventName, handler[, use_capture])$.unbind(element, eventName, handler[, use_capture])$.attr(element, name)read the attributename$.attr(element, name, value)set the attributenamevalue$.create(tagName[, attrs])createElement and set attributes.attrsis a object- Example:
var p = $.create('p')var div = $.create('div', {'class': 'blink'})
- Example:
$.addClass(element, className)$.removeClass(element, className)$.toggleClass(element, className)if class is removed, returnsfalse, otherwise, returnstrue$.hasClass(element, className)
$.window.width()$.window.height()$.scrollX([x])get or set scrollLeft$.scrollY([y])get or set scrollTop
$.history.push(data, title[, url])$.history.replace(data, title[, url])$.history.bind(handler)wherehandler(ev)is a function. work withev.state$.history.unbind(handler)