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
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
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:
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);
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);