Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset the style properties to their CSS defaults in javascript?

Tags:

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" don't work. How can I reset the color to the CSS default from javascript?

like image 831
Calmarius Avatar asked Aug 17 '10 19:08

Calmarius


People also ask

How do I Reset CSS to default?

Use the initial keyword to set a property to its initial value. Use the inherit keyword to make an element's property the same as its parent. Use the revert keyword to reset a property to the value established by the user-agent stylesheet (or by user styles, if any exist).

Can we change CSS properties values using JavaScript?

CSS variables have access to the DOM, which means that you can change them with JavaScript.

Which selector is used to reset the CSS?

This diminutive CSS Reset employs the universal selector ( * ) to reset the padding and margins on all elements to zero. It is often expanded to include border: 0; outline: 0 to also reset these values to zero, nada, zilch.

How do you delete a style in CSS?

Use the style. removeProperty() method to remove CSS style properties from an element, e.g. box. style. removeProperty('background-color') .


2 Answers

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

like image 170
Richard JP Le Guen Avatar answered Nov 04 '22 07:11

Richard JP Le Guen


Set the style property values to the empty string:

 obj.style.color = ""; 
like image 41
Pointy Avatar answered Nov 04 '22 08:11

Pointy