This is plugin for "_". This contains functional API of DOM manipulation.
This project is maintained by 1000ch
This is plugin which provides API for DOM operation for underscore.js/lo-dash.js.
You can build with following command.
$ grunt build
This supports build for following libraries which provide Ajax or Promise.
$ git submodule init
$ git submodule update
$ grunt build
They will be mapped to _.ajax
and _.when
.
Get all elements selected with css selector.
//context is optional parameter.
//if context is empty, element will be searched with document as context
var elements = _.qsa("tagName .className", document);
Get first element selected with css selector.
//context is optional parameter.
//if context is empty, element will be searched with document as context
var element = _.qs("tagName .className", document);
Handle DOMContentLoaded
event.
_.ready(function() {
console.log("DOMContentLoaded");
});
Add event to element.
var clickCallback = function() {
console.log("element is clicked.");
};
var targetElements = _.qsa(".targetClass");
_.on(targetElements, "click", clickCallback);
Remove event from element.
var clickCallback = function() {
console.log("element is clicked.");
};
var targetElements = _.qsa(".targetClass");
_.off(targetElements, "click", clickCallback);
Attach delegated event handler to elements which matches css selector.
var clickCallback = function() {
console.log("span is clicked.");
};
var targetElements = _.qsa(".targetClass");
_.on(targetElements, "click", "button", clickCallback);
Detach delegated event handler from elements.
var clickCallback = function() {
console.log("span is clicked.");
};
var targetElements = _.qsa("targetTag");
_.off(targetElements, "click", "button", clickCallback);
Add class to element.
var targetElemenets = _.qsa(".targetClass");
_.addClass(targetElemenets, "addClassName");
Remove class from element.
var targetElemenets = _.qsa(".targetClass");
_.removeClass(targetElemenets, "removeClassName");
Toggle class of element.
var targetElemenets = _.qsa(".targetClass");
_.toggleClass(targetElemenets, "toggleClassName");
Copyright 1000ch.net
Released under the MIT license.