Skip to content

Instantly share code, notes, and snippets.

@corymartin
Created December 25, 2011 07:15
Show Gist options
  • Select an option

  • Save corymartin/1518841 to your computer and use it in GitHub Desktop.

Select an option

Save corymartin/1518841 to your computer and use it in GitHub Desktop.
jQuery Fast
//
// For simple selectors, these return a jQuery object
// faster via native element selection.
//
(function(window) {
var
doc = window.document,
$ = window.jQuery;
// Select element by id.
// Usage:
// $.byId('txt_fname');
$.byId = function( id ) {
return new $.fn.init( doc.getElementById(id) );
};
// Select elements by tag name.
// Usage:
// $.byClass('div');
$.byTag = function( tagName ) {
return new $.fn.init( doc.getElementsByTagName(tagName) );
};
// Select elements by class name.
// Usage:
// $.byClass('links');
$.byClass = function( className ) {
return doc.getElementsByClassName
? new $.fn.init( doc.getElementsByClassName(className) )
: $('.' + className);
};
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment