Skip to content

Instantly share code, notes, and snippets.

@johnpena
Created July 25, 2012 01:42
Show Gist options
  • Select an option

  • Save johnpena/3173880 to your computer and use it in GitHub Desktop.

Select an option

Save johnpena/3173880 to your computer and use it in GitHub Desktop.
fix for pushstack issues in jquery+chrome
(function () {
jQuery.fn.pushStack = function( elems, name, selector ) {
// Build a new jQuery matched element set
var ret = this.constructor();
// temporary workaround for chrome issue #125148
// http://code.google.com/p/chromium/issues/detail?id=125148
if (!(ret instanceof jQuery.fn.init)) {
console.log("applying pushStack fix");
ret = new jQuery.fn.init();
}
if ( jQuery.isArray( elems ) ) {
push.apply( ret, elems );
} else {
jQuery.merge( ret, elems );
}
// Add the old object onto the stack (as a reference)
ret.prevObject = this;
ret.context = this.context;
if ( name === "find" ) {
ret.selector = this.selector + ( this.selector ? " " : "" ) + selector;
} else if ( name ) {
ret.selector = this.selector + "." + name + "(" + selector + ")";
}
// Return the newly-formed element set
return ret;
};
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment