0

Possible Duplicate:
Creating a CSS class in jQuery

$("< style>span{color:red}< /style>");


jQuery < span>jQuery< /span> jQuery
Community
  • 1
  • 1
Steven Moss
  • 1,237
  • 2
  • 8
  • 7

2 Answers2

6

Heh, interesting idea.

This works if you insert the element into the DOM:

 $('head').append($("<style>span{color:red}</style>"));

jsFiddle

Dynamically fiddling with CSS usually has some side effects, but this should okay: It works fine even in IE6.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • He hasn't actually appended it to the DOM though. If that's what he's trying to do at any rate – JohnP Apr 16 '11 at 17:08
  • 2
    Just a tip for the future: If you are going to be chaining more commands, append gives you the item you are appending to, while appendTo gives you back the item you are appending. In this case, there's not much value, but I like to point it out. – Levi Morrison Apr 16 '11 at 17:21
2

$("<style>span{color:red}</style>").appendTo('head'); ?

Levi Morrison
  • 19,116
  • 7
  • 65
  • 85