Skip to content

Instantly share code, notes, and snippets.

@psiborg
Created January 6, 2012 08:58
Show Gist options
  • Select an option

  • Save psiborg/1569786 to your computer and use it in GitHub Desktop.

Select an option

Save psiborg/1569786 to your computer and use it in GitHub Desktop.
JS Zepto-style Selector
a$('div').css('color:red');
a$('p>span').css('color:red');
a$('#testElem2').html('Hello World!').css('color:red');
a$('#testElem3').html(new Date()).css('background-color:yellow').css('color:red');
var a$ = function (selector) {
return {
dom: Array.prototype.slice.apply(document.querySelectorAll(selector)),
anim: a$.anim,
css: a$.css,
html: a$.html
};
};
a$.html = function (html) {
this.dom.forEach(function (el) {
el.innerHTML = html
});
return this;
};
a$.css = function (style) {
this.dom.forEach(function (el) {
el.style.cssText += ';' + style
});
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment