Skip to content

Instantly share code, notes, and snippets.

@dougwollison
Created April 8, 2015 21:41
Show Gist options
  • Save dougwollison/6c8daf413b2b65257582 to your computer and use it in GitHub Desktop.
Save dougwollison/6c8daf413b2b65257582 to your computer and use it in GitHub Desktop.
jQuery plugin to remove inline css
jQuery.fn.removeStyle = function( property ) {
// Remove all styles if no property is specified
if ( property === null ) {
return this.removeAttr( 'style' );
}
// Split the property list
var proporties = property.split( /\s+/ );
// Loop through each property and remove them
return this.each(function() {
// Determine which method to use based on browser
var remover =
this.style.removeProperty // modern browser
|| this.style.removeAttribute; // old browser (ie 6-8)
for ( var i = 0 ; i < proporties.length ; i++ ) {
remover.call( this.style, proporties[ i ] );
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment