Skip to content

Instantly share code, notes, and snippets.

@shapeshifta78
Created July 13, 2011 16:17
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 shapeshifta78/1080660 to your computer and use it in GitHub Desktop.
Save shapeshifta78/1080660 to your computer and use it in GitHub Desktop.
Javascript Miniframework
//implement missing function
if(!document.getElementsByClassName){
document.getElementsByClassName = function(cl) {
var retnode = [],
myclass = new RegExp('\\b'+cl+'\\b'),
elem = this.getElementsByTagName('*');
for (var i = 0, max = elem.length; i < max; i++) {
var classes = elem[i].className;
if (myclass.test(classes)){
retnode.push(elem[i]);
}
}
return retnode;
};
}
//framework functions
function $(id){ return document.getElementById(id); }
function html(id, html){ $(id).innerHTML = html; }
function css(id, style){ $(id).style.cssText += ';'+style;}
function $$(cl){ return document.getElementsByClassName(cl); }
//testrun
html('test','this is an awesome text');
css('test','color:red;background-color:blue');
var groups = $$('group');
for (var i = 0, max = groups.length; i < max; i++){
groups[i].innerHTML = 'element ' + i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment