Possible Duplicate:
how to remove css property using javascript?
I have this javascript:
var div = document.getElementById('myDiv');
div.style.width = '300px';
div.style.height = '200px';
...
and so on...
Later on I am faced with the need of removing a property (not changing its value, really removing meaning: like I had not set that before)
I coded something like this:
Only solution n.3 seems to work but even so... I am not sure this is the correct way to do it (I am only using chrome to test this)
Does anybody know what's the correct way ? which works across all proper browsers ?
Thanks
You can use inherit
or initial
value. http://www.w3.org/TR/css3-values/#common-keywords
There's no "correct way". Microsoft once invented style.removeAttribute(), but it's not supported. The best way is to set it to the standard-value.
Edit: As dystroy mentioned, setting it to "" resets it in all browsers, so that would be the best way.
Here you go:
div.style.height = "auto"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With