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:
- div.style.height = undefined;
- div.style.height = null;
- div.style.height = ”;
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
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.