Skip to content

Instantly share code, notes, and snippets.

@wvega
Created July 15, 2011 23:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wvega/1085787 to your computer and use it in GitHub Desktop.
Save wvega/1085787 to your computer and use it in GitHub Desktop.
jQuery Sandbox
$.fn.sandbox = function(fn) {
var element = $(this).clone(), result;
// make the element take space in the page but invisible
element.css({visibility: 'hidden', display: 'block'}).insertAfter(this);
// to override any display: none !important you may have been using
element.attr('style', element.attr('style').replace('block', 'block !important'));
result = fn.apply(element);
element.remove();
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment