Home > other >  How to add a CSS like styling in jQuery
How to add a CSS like styling in jQuery

Time:10-28

I am using Spring MVC and we are saving some styles directly in our database. There is no CSS file for these styles. Now my problem is that I have styling text like below:

.className { 
    background-color: red; color: blue;
} 
.anotherClassName { 
    padding: 15px; margin: 10px;
} 

I am aware of jQuery .css method but its syntax is css("propertyname","value");

How can use my styling from jQuery?

CodePudding user response:

As simple as this...

const myCssString = `.className { 
    background-color: red; color: blue;
} 
.anotherClassName { 
    padding: 15px; margin: 10px;
}`;

$('<style>', {
  text: myCssString
}).appendTo('head');
  • Related