Created
November 13, 2014 23:31
-
-
Save volter9/db8d2d815503f4d1c50e to your computer and use it in GitHub Desktop.
Better than jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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