Skip to content

Instantly share code, notes, and snippets.

@volter9
Created November 13, 2014 23:31
Show Gist options
  • Save volter9/db8d2d815503f4d1c50e to your computer and use it in GitHub Desktop.
Save volter9/db8d2d815503f4d1c50e to your computer and use it in GitHub Desktop.
Better than jQuery
var MooQuery = function (query) {
this.elements = Array.prototype.splice.call(document.querySelectorAll(query), 0);
};
MooQuery.prototype = {
constructor: MooQuery,
each: function (callback) {
this.elements.map(callback);
},
};
// Examples
// Basic usage
// Make all links red
var links = new MooQuery('a');
links.each(function (element) {
element.style.color = '#f00';
});
// Hide elements
MooQuery.prototype.hide = function () {
this.each(function (element) {
element.style.display = 'none';
});
};
links.hide();
// Wow...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment