Skip to content

Instantly share code, notes, and snippets.

@blendsdk
Created December 3, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blendsdk/2eca0c9b5e8fd1cc780c to your computer and use it in GitHub Desktop.
Save blendsdk/2eca0c9b5e8fd1cc780c to your computer and use it in GitHub Desktop.
Something like what JQuery does
console.clear();
var $ = function(selector) {
var list = document.querySelectorAll(selector)
var each = function(callback) {
return function() {
for(var a = 0; a != list.length; a++) {
var obj = list[a];
callback.apply(obj,arguments);
}
return list;
}
}
list.show = each(function(){
this.style.display = '';
});
list.hide = each(function(){
this.style.display = 'none';
});
list.bg = each(function(color){
this.style.backgroundColor = color || 'red';
})
return list;
}
$('pre').bg('blue').hide().show().bg('yellow');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment