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!