-1

I have a CSS elements defined as below:

.myRedClass
{
  background-color:red;
}

And it is assigned to many Divs( that are having similar appearance). At some point i need to assign some left-margin also. What i am currently doing is; I will add and remove a Predefined Class .redClass-margin{margin-left:10px} to each of the required div. The code for this is:

$( "myDiv1" ).addClass( "redClass-margin" );
$( "myDiv2" ).addClass( "redClass-margin" );
$( "myDiv3" ).addClass( "redClass-margin" );

and so on... Instead for this Can i do changes in the existing css class. Is their any possibility to change the .myRedClass like the following :

.myRedClass
    {
      background-color:red;
      margin-left:10px;
    }

Either Through script or through c#

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88

2 Answers2

2

You can't edit an existing css stylesheet.

There's a different approach though. If you just want to find all divs that have class myRedClass, and add redClass-margin, you can find them all with jquery and add class.

$('.myRedClass').addClass('redClass-margin');
Eric Guan
  • 15,474
  • 8
  • 50
  • 61
0

I really don't get why you want to do this I would just create a new classand append the class name to each element like Eric mentioned.

However there is a here that tell you how to do what your asking.

Alternatively you could inject rules into your style sheet, again a weird way to do it. See this.

Community
  • 1
  • 1
D3TXER
  • 152
  • 2
  • 13