3

Possible Duplicate:
Is it possible to remove inline styles with jQuery?

I'm building a javascript application doing something with images.

At some point I'm having an element with inline style css-properties (width & height). I want to remove these properties with javascript/jQuery. I know you can set css-properties with .css() method.

Is there a way to remove the properties like you do with .removeAttr()? Potential other css-properties should not be removed.

Community
  • 1
  • 1
Willem de Wit
  • 8,604
  • 9
  • 57
  • 90
  • 1
    Sorry, the answer can be found [here][1]. [1]: http://stackoverflow.com/questions/2465158/possible-to-remove-inline-styles-with-jquery – Willem de Wit Jul 27 '12 at 07:36
  • Please check here (Stackoverflow) before posting any questions. It helps more more to reach a answer very fast. – Mr. Black Jul 27 '12 at 07:44

2 Answers2

15

try this :

$('div').css({'width' : '', 'height' : ''});

or if there is a class, you remove it by:

$('div').removeClass('someClass');
Shreedhar
  • 5,502
  • 3
  • 22
  • 27
4

From the documentation:

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 the style property. It does not, however, remove a style that has been applied with a CSS rule in a stylesheet or element.

So what you need, is just this:

$('element').css({width:'', height:''});
Engineer
  • 47,849
  • 12
  • 88
  • 91