Kermode

/ˈkɜːrmoʊd/
The Spirit Bear

Written by Gray Gilmore

Kermode

I make websites for a living. I love CSS and building simple and modular stylesheets. Somewhere along the way I also turned into a Ruby developer. Life comes at you fast I guess. You can read my resume to learn about my journey so far.

Other Projects

Say Hello

You can find me as @graygilmore on several platforms:

Good ol' fashion email works, too: hello@kermode.co

You can subscribe to this blog via RSS: XML, JSON

Remove Specific Inline Style with jQuery

Recently in a project I needed to remove inline styles after an animation completed. It looked something like this:

$('.some-class').animate({
  something: value
}, function () {
  $(this).attr('style','');
});

This was working great until I realized that I need to keep some of those styles and I was really only wiping them all out to remove a specific style. Thus began the hunt for the best solution to find how to remove a specific inline style using jQuery.

It turns out the answer was staring at me all along. I can use the exact same method I was using to remove the entire style attribute. The answer looks like this:

$('.some-class').css('left','');

Simply by providing a blank value, the left style declaration is completely removed. No silly regex required!