37 lines
860 B
JavaScript
37 lines
860 B
JavaScript
// dom.js
|
|
// utility functions for managing DOM elements
|
|
|
|
var selectOne = function (selector, el) {
|
|
if (!el) {
|
|
el = document;
|
|
}
|
|
return el.querySelector(selector);
|
|
};
|
|
|
|
var selectAll = function (selector, el) {
|
|
if (!el) {
|
|
el = document;
|
|
}
|
|
return Array.prototype.slice.call(el.querySelectorAll(selector));
|
|
};
|
|
|
|
var hide = function (el) {
|
|
if (el) {
|
|
el.setAttribute('style', 'display:none;');
|
|
return el;
|
|
}
|
|
};
|
|
|
|
var show = function (el) {
|
|
if (el) {
|
|
el.removeAttribute('style');
|
|
return el;
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
$: selectOne, // `$('.myclass', baseElement)` - returns selected element or undefined
|
|
$$: selectAll, // `$$('.myclass', baseElement)` - returns array of selected elements
|
|
hide: hide, // `hide(someElement)` - hide passed dom element
|
|
show: show // `show(someElement)` - show passed dom element
|
|
}; |