istesequi
Version:
Lightweight and intuitive javascript library
23 lines (17 loc) • 617 B
JavaScript
/**
* .adjacent(position, text)
*
* Add text in the specified position. It is used by other functions
*/
u.prototype.adjacent = function(position, text, data) {
// Loop through all the nodes
return this.each(function(node) {
u(data || [""]).each(function(d, i){
// Allow for callbacks that accept some data
var tx = (typeof text === 'function') ? text(d, i) : text;
// http://stackoverflow.com/a/23589438
// Ref: https://developer.mozilla.org/en-US/docs/Web/API/Element.insertAdjacentHTML
node.insertAdjacentHTML(position, tx);
});
});
};