Skip to content

Instantly share code, notes, and snippets.

@filipsalo
Created April 13, 2011 15:51
Show Gist options
  • Save filipsalo/917801 to your computer and use it in GitHub Desktop.
Save filipsalo/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