How do I unset an element's CSS attribute using jQuery?
From the jQuery docs:
Setting the value of a style property to an empty string — e.g.
$('#mydiv').css('color', '')
— removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's.css()
method, or through direct DOM manipulation of thestyle
property. It does not, however, remove a style that has been applied with a CSS rule in a stylesheet or<style>
element.
I think you can also do:
$('#element').css('background-color', '');
That's what I used to do a long time ago for the display
property in plain-old-javascript to show/hide a field.
Actually, the syntax I thought was incorrect (with null
) seems to be working -- my selector was just improperly formed, and thus yielding no elements. D'oh!