Last active
October 1, 2015 12:48
-
-
Save barneycarroll/1995017 to your computer and use it in GitHub Desktop.
Get rid of Sizzle's IE custom attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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