Skip to content

Instantly share code, notes, and snippets.

@stanwilsonjr
Created February 8, 2011 22:06
Show Gist options
  • Save stanwilsonjr/817376 to your computer and use it in GitHub Desktop.
Save stanwilsonjr/817376 to your computer and use it in GitHub Desktop.
Curry function that creates a selector function that can be used on the DOM
function get(container,selector){
return function(element){
return container[selector](element);
}
};
//used
var getById = get(document,"getElementById"), // creates get by id function equivalent to document.getElementById()
content = getById("element_id").innerHTML, // returns element with the id "element_id" and its contents via innerHTML
testDiv = getById("test") ; /// returns <div id="test"><span>im inside</span></div>
get(testDiv,"getElementsByTagName")("span")[0].innerHTML ); /// returns "im inside"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment