-1

can anyone give me example how to insert tags css into the .css file using jquery

I have tried several times still can not only able to add css style tags into the head

bro no
  • 43
  • 4

3 Answers3

1

You don't need & can't with jQuery - you can manipulate the CSS of elements directly - jQuery will parse and add the style attribute for the target element\s.

For a more general approaches who has crossbrowser support in case you are trying to use several different stylesheets read my answer about alternate style-sheets

You can use plain JS to push some rules or even create new stylesheets using the document.styleSheets object. For more reading and good examples:

Community
  • 1
  • 1
Shlomi Hassid
  • 6,500
  • 3
  • 27
  • 48
0

This is a pretty unusual task so jQuery doesn't have special handling for it. You can accomplish this with basic javascript however.

Your stylesheets are available with:

document.styleSheets

You can add to them with insertRule:

document.styleSheets[0].insertRule("body { width: 100%; }", 1);
Will Reese
  • 2,801
  • 2
  • 15
  • 27
0
var sheet = (function () {
var style = document.createElement("style");
style.appendChild(document.createTextNode(""));
document.head.appendChild(style);
return style.sheet;
})();
sheet.insertRule("@media all { body { background : red } body { color : black } }", 0);
Lalji Tadhani
  • 14,041
  • 3
  • 23
  • 40