Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jquery Replacement Utility Code
//this is just the base code. To see a usage example, see Jquery-Replacement-Utility-Code-example-code.js
var getElement = function(selector) { // or var $ = function(selector) {
var wrapper = document.querySelector(selector);
// get Dom wrapper.
//function to add custom functions to the wrapper.
this.addFunction = function(name, code) {
// if code is undefined, assume name is an object with name:function pairs
//enumerate the object name
if (!code) {
for (var key in name) {
//make sure item is not a prototype
if (name.hasOwnProperty(key)) {
var value = name[key];
//set function name in the wrapper to the value(function code)
wrapper[key] = value;
}
}
}
//there is only one function being defined. Set the name to the function(code)
else {
wrapper[name] = code;
}
};
//add utility functions here
return wrapper;
};

jQuery Utility Code Wrapper

Ths script is useful if you are making a libary that needs to do some jQuery-like functonality or are trying to make a jQuery plugin into a Javascript Liabry without jQuery. You can find some utility code to replace certain jQuery functions at http://youmightnotneedjquery.com/ To see usage example, see the Jquery-Replacement-Utility-Code-example-code.js

This code is in the public domain (however a link back to this page would be appreciated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment