Return to Snippet

Revision: 61389
at December 10, 2012 12:53 by o0110o


Updated Code
var $ = function(selector, node) { // Bare-Bones Selector Engine
    var selector, node;
    selector = selector.trim();
    node = node || document.body;
    if (selector != null) {
        return Array.prototype.slice.call(node.querySelectorAll(selector), 0);
    }
}

Array.prototype.put = function(html) {
    for (var i = 0; i < this.length; i++) {
        this[i].innerHTML = html;
    }
    return this;
}
        
$('div').put('yay!');

Revision: 61388
at December 9, 2012 10:11 by o0110o


Initial Code
var $ = function(selector, node) { // Bare-Bones Selector Engine
    var selector, node;
    selector = selector.trim();
    node = node || document.body;
    if (selector != null) {
        return Array.prototype.slice.call(node.querySelectorAll(selector), 0);
    }
}

Array.prototype.put = function(markup) {
    for (var i = 0; i < this.length; i++) {
        this[i].innerHTML = markup;
    }
}
        
$('div').put('yay!');

Initial URL

                                

Initial Description
This is a very basic wrapper for querySelectorAll. Just add prototypes and whatever else you need.

Initial Title
Bare-Bones Selector Engine

Initial Tags
javascript, class

Initial Language
JavaScript