Created
July 13, 2011 16:17
-
-
Save shapeshifta78/1080660 to your computer and use it in GitHub Desktop.
Javascript Miniframework
This file contains 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
//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