views:

38

answers:

2

On a php generated page there are several elements like this:

<td class="defaultTDStyle" style="color:userDefinedCustomColor" id="myTDId"></td>

So there is a default style and I apply several extra styles that override the style defined in the CSS.

Is there a way to remove these added styles from javascript? It seems the obj.style.color="default" and obj.style.color="auto" not works. How can I reset the color to the CSS default from javascript?

+1  A: 

Try setting the attributes to null:

 obj.style.color = null;
Pointy
+1  A: 

If recollection serves, obj.style.color="" should work... I don't know if it's right though.

LeguRi
I think that only resets styles set via JavaScript. But in this case, the original style is inline.
casablanca
It works, and it is right, although since the style is added in markup, you might want to do `obj.removeAttribute('style')` as well for good measure.
MooGoo
@casablanca well it sure does work in Firefox, regardless of where the on-element style was set.
Pointy
You're right, I just tested it and it works. It seems inline styles make their way into `obj.style` so you *can* reset them by emptying the string, but not those declared in a stylesheet.
casablanca
Thx for the quick answer. It works on Firefox. I hope it works on the other browsers too. I have only Ubuntu now and there is Firefox only.
Calmarius
@Calmarius - again, I don't know if this is _right_ - maybe it violates some standard or something. _I highly recommend you check it in other browsers_.
LeguRi
@MooGoo - I think removing the whole style attribute could be drastic. What if there are other properties they don't want to reset/remove?
LeguRi
I understand "restore default style" to mean the style of the element sans any inline attributes. If you are talking about individual style rules, then no you would not want to remove the whole style attribute.
MooGoo