Skip to content

Instantly share code, notes, and snippets.

@filipsalomonsson
Created April 13, 2011 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipsalomonsson/917801 to your computer and use it in GitHub Desktop.
Save filipsalomonsson/917801 to your computer and use it in GitHub Desktop.
Untested plugin for getting the inverse of the last selection in jQuery
(function($) {
$.fn.inverse = function() {
var prevSelector = this.prevObject.selector,
suffix = this.selector.slice(prevSelector.length);
if (suffix.charAt(0) === " ") {
// Last action was a find
return this.prevObject.find(":not(" + suffix.slice(1) + ")");
} else {
return this.prevObject.not(this);
}
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment