-1

I will explain the question using an example. Suppose I have a css class called 'custom-background', and on a button click, I wish to change the background color property of all elements associated with this class to, say, red. On another click, I wish to change it to yellow, and there might be a case where I wish to remove the background-color override coming due to association with this class.

Is there a way to achieve this using JavaScript? I know I can specifically override properties of elements associated with the class, but I don't think I can completely remove a particular attribute. Therefore, I am looking for a way to modify the CSS attributes associated with a class.

alpha_ulrich
  • 536
  • 5
  • 21
  • Did you do any research? https://developer.mozilla.org/en/docs/Web/API/Element/classList – jonrsharpe Apr 15 '17 at 13:56
  • I know about how to add or remove classes from DOM elements. The question is not about that, but rather, can you somehow edit CSS properties of a known class. And to answer your question, yes I did do some research, but was not able to find any satisfactory solution. For now, I'm planning to simply keep overriding properties of all elements belonging to target class, but really want a more elegant solution. – alpha_ulrich Apr 15 '17 at 14:00

1 Answers1

0

If i understood what you meant,

you can reverse it back to default. .class{background:none} document.getElementsByClassName('class').style.backgroundColor="none";