Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Last active October 1, 2015 12:48
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 barneycarroll/1995017 to your computer and use it in GitHub Desktop.
Save barneycarroll/1995017 to your computer and use it in GitHub Desktop.
Get rid of Sizzle's IE custom attributes
/*
In IE, Sizzle has to create custom attributes to be able to travel the DOM intelligently. The custom attributes are lengthy and nasty, and can often screw up your code if you rely on parsing markup. fizzleSizzle wipes all that stuff out.
*/
// Pass in a string of markup and get it back without Sizzle's shizzle
var fizzleShizzle = function(x){
return x.replace(/(nodeIndex|sizcache|sizset)[\w\d]*(="[^"]*")*/gi,'');
};
(function($){
if(!$) return;
// Strip the shizzle from the DOM; pass a truthy argument to do the same for all children
$.fn.fizzleShizzle = function(deep){
var $el = deep ? this.add(this.find('*')) || this;
// Iterate through the selection
$el.each(function(){
var
el = this,
ats = el.attributes;
// Iterate through attributes
$.each(ats,function(i,x){
// Is it one of these?
if(/^nodeIndex|^sizcache|^sizset/.test(x))
// Fizzle it
el.removeAttribute(x);
});
});
return this;
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment